Hibernate4:基于XML的配置文件

Hibernate4的配置文件与前面的版本基本是一致的:

hibernate.cfg.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE hibernate-configuration PUBLIC 
 3     "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
 4     "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
 5 
 6 <hibernate-configuration>
 7     <session-factory>
 8         <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
 9         <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/addtocart</property>
10         <property name="hibernate.connection.username">postgres</property>
11         <property name="hibernate.connection.password">postgres</property>
12         <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
13         <property name="hibernate.show_sql">true</property>
14         
15         <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
16         <property name="hibernate.c3p0.max_size">10</property>
17         <property name="hibernate.c3p0.min_size">1</property>
18         <property name="hibernate.c3p0.max_statements">3</property>
19         <property name="hibernate.c3p0.timeout">30</property>
20         <property name="hibernate.c3p0.acquire_increment">1</property>
21         <property name="hibernate.c3p0.idle_test_periodt">10</property>
22         
23         <mapping resource="com/xxx/yyy.hbm.xml" />
24         <mapping resource="com/xxx/yyy.hbm.xml" />
25     </session-factory>
26 </hibernate-configuration>

 hibernate.hbm.xml

 1 <?xml version="1.0"?>
 2 <!DOCTYPE hibernate-mapping PUBLIC 
 3         "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
 4         "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
 5 
 6 <hibernate-mapping package="com.xxx">
 7     <class name="YYY" table="yyy">
 8         <id name="id" column="id" type="integer">
 9             <generator class="sequence">
10                 <param name="sequence">xxx_id_seq</param>
11             </generator>
12         </id>
13         <property name="aaa" column="AAA" type="java.lang.String" />
14         <property name="bbb" column="BBB" type="java.lang.String" />
15     </class>
16 </hibernate-mapping>

 

posted on 2013-10-14 11:01  月涛阑珊  阅读(434)  评论(0)    收藏  举报