Hibernate的配置文件

2008-02-23 09:28:47来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

Hibernate的单独配置和结合Spring的配置:

下面一一展示一下,主要以MySQL数据库为例:

Hibernate.cfg.XML

<?xml version='1.0' encoding='gb2312'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"
http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.JDBC.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">810606</property>
<property name="hibernate.connection.pool.size">20</property>
<property name="hibernate.show_sql">true</property>
<property name="jdbc.fetch_size">50</property>
<property name="jdbc.batch_size">25</property>
<property name="jdbc.use_scrollable_resultset">false</property>
<property name="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</property>

<!-- Mapping files -->
<mapping resource="user.hbm.xml"/>
</session-factory>
</hibernate-configuration>


第二种是和Spring的AOP结合

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "
http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<description>Spring Quick Start</description>
<!-- datasource -->
<bean id="datasource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost/test</value>
</property>
<property name="username">
<value>sa</value>
</property>
<property name="password">
<value>810606</value>
</property>
</bean>
<!-- hibernate support -->
<bean id="sessionFactory"
class="org.springFramework.orm.hibernate.LocalSessionFactoryBean"
>
<property name="dataSource">
<ref local="datasource"/>
</property>
<property name="mappingResources">
<list>
<value>test/bcxy/spring/dao/user.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
net.sf.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">
true
</prop>
</props>
</property>
</bean>
<!-- hibernate dao -->
<bean id="hibernatedao"
class="com.bcxy.spring.dao.TestDAO"
>
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>

上一篇: 对package的理解
下一篇: Eclipseの日本語のコンピュータの語彙(ごい)

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:可以设置背景的JPanel!!

下一篇:Tom小猫,让我看清你的五脏六腑(一)