Hibernate 配置文件

映射文件(.hbm.xml)

 1 <?xml version="1.0" encoding="UTF-8"?>
 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     <!-- ORM元数据  表对象关系映射文件 
 6         package : 配置该配置文件中类所在的包.  -->
 7  <hibernate-mapping package="com.itheima.a_hello" >
 8      <!-- class: 配置实体与表的关系
 9          name : 填写实体的完整类名
10          table: 与实体对应表的名称
11          dynamic-insert:动态插入 默认值是false
12                          true=>如果字段值为null,不参与insert语句
13          dynamic-update:动态更新  默认值"false"
14                           true=> 没改动过的属性,将不会生成到update语句中
15       -->
16      <class name="User" table="t_user"  >
17          <!-- id: 配置实体与表中 id对应
18              name: user对象中标识主键的属性名称
19              column: 主键在表中的列名
20              length: 列的数据长度(为varchar类型)
21              unsaved-value(不常用): 指定主键为什么值时,当做null来处理.
22             access(强烈推荐不要用):field 那么在操作属性时,会直接操作对应的字段而不是get/set方法
23           -->
24         <id name="id" column="id" length="255"   >
25             <!-- generator:主键生成策略
26                      1.increment  Hibernate自己生成主键. 先从数据库中查询最大的ID值,将ID值加1作为新的主键
27                     2.identity  依赖于数据的主键自增功能
28                     3.sequence    序列,依赖于数据中的序列功能(Oracle).
29                     4.hilo(纯了解,永远用不到) : Hibernate自己实现序列的算法,自己生成主键. (hilo算法 )
30                     5.native 自动根据数据库判断,三选一. identity|sequence|hilo
31                     6.uuid  生成32位的不重复随机字符串当做主键
32                     
33                     7.assigned 自己指定主键值. 表的主键是自然主键时使用.
34              -->
35             <generator class="uuid"></generator>
36         </id>     
37         <!-- property : 实体中属性与表中列的对应
38              name : 实体中属性名称
39              column : 表中列的名称
40              length : 数据长度
41              precision: 小数点后的精度
42              scale:    有效位数
43              insert(一般不用): 该属性是否加入insert语句.
44              update(一般不用): 该属性是否加入update语句.
45              not-null : 指定属性的约束是否使用 非空
46              unique : 指定属性的约束是否使用 唯一
47          -->
48          <!-- 
49              type: 表达该属性的类型
50              可以用三种方式指定属性
51              java类型                  数据库类型指定            Hibernate类型指定
52              java.lang.String    varchar                string
53           -->
54         <property name="name" column="name" update="true" type="string" ></property>
55         <property name="password" column="password"></property>
56          <property name="sal" column="sal" precision="2" scale="3" ></property>
57      </class>
58  </hibernate-mapping>
User.hbm.xml

  一对多的映射文件:

 1 <?xml version="1.0" encoding="UTF-8"?>
 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  <hibernate-mapping package="com.itheima.domain" >
 6      <class name="Customer" table="t_customer"  >
 7         <id name="id" column="id"    >
 8             <generator class="native"></generator>
 9         </id>     
10         <property name="name" column="name" type="string" ></property>
11          
12          <!-- 表达一对多关系中的集合
13              name:集合的属性名称
14              inverse: 是否将关系的维护反转给对方. 默认值: false
15                     true: 在Customer 中 放弃维护外键关系
16                     
17              cascade :级联操作
18                  save-update:级联保存,级联修改. 保存A时,同时保存B. 
19                 delete:删除A,同时删除B,AB都不存在
20                 delete-orphan:孤儿删除,解除关系,同时将B删除,A存在的。
21                 如果需要配置多项,使用逗号分隔。<set cascade="save-update,delete">
22                 
23                 all : save-update 和 delete 整合
24                 all-delete-orphan : 三个整合
25                  
26           -->
27          <set name="orders" inverse="false" cascade="all-delete-orphan"  >
28              <!--
29                  key 用来描述外键
30                  column : 外键的值
31                -->
32              <key column="cid" ></key>
33              <!-- one-to-many 表达, Customer 与orders 的关系是一对多
34                  class: 表达关联的另一方的完整类名
35               -->
36              <one-to-many class="Order" />
37          </set>
38      </class>
39  </hibernate-mapping>
多.hbm.xml
 1 <?xml version="1.0" encoding="UTF-8"?>
 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  <hibernate-mapping package="com.itheima.domain" >
 6      <class name="Order" table="t_order"  >
 7         <id name="id" column="id"    >
 8             <generator class="native"></generator>
 9         </id>     
10         <property name="name" column="name" type="string" ></property>
11          
12          <!-- 表达多对一关系 
13              name: 引用的属性名称
14              column: 外键的列名
15              class: 我引用的Order的完整类名
16          -->
17          <many-to-one name="customer" column="cid" class="Customer"   ></many-to-one>
18      </class>
19  </hibernate-mapping>
一.hbm.xml

多对多映射文件

 1 <?xml version="1.0" encoding="UTF-8"?>
 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     <!-- ORM元数据  表对象关系映射文件 
 6         package : 配置该配置文件中类所在的包.  -->
 7  <hibernate-mapping package="com.itheima.domain" >
 8      <class name="Student" table="t_student"   >
 9         <id name="id" column="id"    >
10             <generator class="native"></generator>
11         </id>     
12         <property name="name" column="name" ></property>
13         
14         <!-- 多对多关系 -->
15         <!-- 
16             set 表达集合
17                 name: 集合的属性名
18                 table:多对多中间表的表名
19             key 表达外键
20                 column:引用我的外键名
21             many-to-many 表达多对多
22                 class : 集合引用方的类型
23                 column:对方在中间表的外键名
24          -->
25         <set name="courses" table="t_student_course" inverse="false" cascade="save-update"  >
26             <key column="sid" ></key>
27             <many-to-many class="Course" column="cid" ></many-to-many>
28         </set>
29     
30      </class>
31  </hibernate-mapping>
javabean1.hbm.xml
 1 <?xml version="1.0" encoding="UTF-8"?>
 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     <!-- ORM元数据  表对象关系映射文件 
 6         package : 配置该配置文件中类所在的包.  -->
 7  <hibernate-mapping package="com.itheima.domain" >
 8      <class name="Course" table="t_course"  >
 9         <id name="id" column="id"    >
10             <generator class="native"></generator>
11         </id>     
12         <property name="name" column="name" ></property>
13         
14         <set name="students" table="t_student_course" inverse="true" >
15             <key column="cid" ></key>
16             <many-to-many class="Student" column="sid"  ></many-to-many>
17         </set>
18      </class>
19  </hibernate-mapping>
javabean2.hbm.xml

单对单映射文件

  方式一:

 1 <?xml version="1.0" encoding="UTF-8"?>
 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  <hibernate-mapping package="com.itheima.domain" >
 6      <class name="Address" table="t_Address"   >
 7         <id name="id" column="id"    >
 8             <generator class="native"></generator>
 9         </id> 
10             
11         <property name="name" column="name" type="string" ></property>
12          <!-- 
13          unique : 唯一,外键唯一.
14           -->
15          <many-to-one name="company" class="Company" column="cid" unique="true" ></many-to-one>
16      </class>
17  </hibernate-mapping>
Address.hbm.xml
 1 <?xml version="1.0" encoding="UTF-8"?>
 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  <hibernate-mapping package="com.itheima.domain" >
 6      <class name="Company" table="t_Company"   >
 7         <id name="id" column="id"    >
 8             <generator class="native"></generator>
 9         </id> 
10             
11         <property name="name" column="name" type="string" ></property>
12         <!-- 配置一对一
13         one-to-one : 默认使用主键同步策略完成一对一的表关系体现.
14         property-ref : 指定company在一对一关联时 ,指向哪个属性.
15          -->
16         <one-to-one name="address" class="Address" property-ref="company" > </one-to-one>
17      </class>
18  </hibernate-mapping>
Company.hbm.xml

  方式二:

 1 <?xml version="1.0" encoding="UTF-8"?>
 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  <hibernate-mapping package="com.itheima.domain" >
 6      <class name="Address" table="t_Address"   >
 7         <id name="id" column="id"    >
 8         <!-- foreign: 该主键既是主键又是外键 -->
 9             <generator class="foreign">
10             <!-- 作为外键时引用哪个属性 -->
11                 <param name="property">company</param>
12             </generator>
13         </id> 
14             
15         <property name="name" column="name" type="string" ></property>
16         <!-- 配置一对一关系 -->
17         <one-to-one name="company" class="Company" constrained="true"  ></one-to-one>
18      </class>
19  </hibernate-mapping>
Address.hbm.xml
 1 <?xml version="1.0" encoding="UTF-8"?>
 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  <hibernate-mapping package="com.itheima.domain" >
 6      <class name="Company" table="t_Company"   >
 7         <id name="id" column="id"    >
 8             <generator class="native"></generator>
 9         </id> 
10             
11         <property name="name" column="name" type="string" ></property>
12         <!-- 配置一对一
13         one-to-one : 默认使用主键同步策略完成一对一的表关系体现.
14         cascade:
15         fetch:
16         lazy:
17          -->
18         <one-to-one name="address" class="Address"  > </one-to-one>
19      </class>
20  </hibernate-mapping>
Company.hbm.xml

核心配置文件(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://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
 5 
 6 <hibernate-configuration>
 7     <session-factory>
 8         <!-- property 元素用于配置Hibernate中的属性
 9             键:值 
10           -->
11           <!-- hibernate.connection.driver_class : 连接数据库的驱动  -->
12         <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
13           <!-- hibernate.connection.username : 连接数据库的用户名 -->
14         <property name="hibernate.connection.username">root</property>
15           <!-- hibernate.connection.password : 连接数据库的密码 -->
16         <property name="hibernate.connection.password">1234</property>
17           <!-- hibernate.connection.url : 连接数据库的地址,路径 -->
18         <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/EE19Day01</property>
19         
20         <!-- show_sql: 操作数据库时,会 向控制台打印sql语句 -->
21         <property name="show_sql">true</property>
22         <!-- format_sql: 打印sql语句前,会将sql语句先格式化  -->
23         <property name="format_sql">true</property>
24         <!-- hbm2ddl.auto: 生成表结构的策略配置
25              update(最常用的取值): 如果当前数据库中不存在表结构,那么自动创建表结构. 
26                      如果存在表结构,并且表结构与实体一致,那么不做修改
27                      如果存在表结构,并且表结构与实体不一致,那么会修改表结构.会保留原有列.
28              create(很少):无论是否存在表结构.每次启动Hibernate都会重新创建表结构.(数据会丢失)
29              create-drop(极少): 无论是否存在表结构.每次启动Hibernate都会重新创建表结构.每次Hibernate运行结束时,删除表结构.
30              validate(很少):不会自动创建表结构.也不会自动维护表结构.Hibernate只校验表结构. 如果表结构不一致将会抛出异常.
31           -->
32         <property name="hbm2ddl.auto">update</property>
33         
34         <!-- 数据库方言配置 
35          org.hibernate.dialect.MySQLDialect (选择最短的)
36          -->
37         <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
38         
39         
40         
41         <!-- hibernate.connection.autocommit: 事务自动提交  -->
42         <property name="hibernate.connection.autocommit">true</property>
43         <!-- 将Session与线程绑定=> 只有配置了该配置,才能使用getCurrentSession -->
44         <property name="hibernate.current_session_context_class">thread</property>
45         <!-- 引入ORM 映射文件 
46             填写src之后的路径
47          -->
48         <mapping resource="com/itheima/a_hello/User.hbm.xml"/>
49     </session-factory>
50 </hibernate-configuration>
hibernate.cfg.xml

工具类

 1 package com.ittest.hibernate.utils;
 2 
 3 import org.hibernate.SessionFactory;
 4 import org.hibernate.cfg.Configuration;
 5 
 6 public class Hibernate_session_Utils {
 7 
 8     private Hibernate_session_Utils(){
 9         
10     }
11     private static SessionFactory sf;
12     
13     static{
14         sf =  new Configuration().configure().buildSessionFactory();
15         
16         Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
17             
18             @Override
19             public void run() {   //设置程序结束自动关闭该sessionfactory。
20             /*    System.out.println("虚拟机关闭!释放资源");*/
21                 sf.close();
22             }
23         }));
24     }
25     
26     public static org.hibernate.Session openSession(){
27         return sf.openSession();
28     }
29     
30     public static org.hibernate.Session getCurrentSession(){
31         return sf.getCurrentSession();
32     }
33     
34     /*public static void main(String [] args){
35         System.out.println(openSession());
36     }*/
37     
38 }
Hibernate_session_utile.java

原配置文件(hibernate.properties)

  1 ######################
  2 ### Query Language ###
  3 ######################
  4 
  5 ## define query language constants / function names
  6 
  7 hibernate.query.substitutions yes 'Y', no 'N'
  8 
  9 
 10 ## select the classic query parser
 11 
 12 #hibernate.query.factory_class org.hibernate.hql.classic.ClassicQueryTranslatorFactory
 13 
 14 
 15 
 16 #################
 17 ### Platforms ###
 18 #################
 19 
 20 ## JNDI Datasource
 21 
 22 #hibernate.connection.datasource jdbc/test
 23 #hibernate.connection.username db2
 24 #hibernate.connection.password db2
 25 
 26 
 27 ## HypersonicSQL
 28 
 29 hibernate.dialect org.hibernate.dialect.HSQLDialect
 30 hibernate.connection.driver_class org.hsqldb.jdbcDriver
 31 hibernate.connection.username sa
 32 hibernate.connection.password
 33 hibernate.connection.url jdbc:hsqldb:./build/db/hsqldb/hibernate
 34 #hibernate.connection.url jdbc:hsqldb:hsql://localhost
 35 #hibernate.connection.url jdbc:hsqldb:test
 36 
 37 ## H2 (www.h2database.com)
 38 #hibernate.dialect org.hibernate.dialect.H2Dialect
 39 #hibernate.connection.driver_class org.h2.Driver
 40 #hibernate.connection.username sa
 41 #hibernate.connection.password
 42 #hibernate.connection.url jdbc:h2:mem:./build/db/h2/hibernate
 43 #hibernate.connection.url jdbc:h2:testdb/h2test
 44 #hibernate.connection.url jdbc:h2:mem:imdb1
 45 #hibernate.connection.url jdbc:h2:tcp://dbserv:8084/sample;     
 46 #hibernate.connection.url jdbc:h2:ssl://secureserv:8085/sample;     
 47 #hibernate.connection.url jdbc:h2:ssl://secureserv/testdb;cipher=AES
 48 
 49 ## MySQL
 50 
 51 #hibernate.dialect org.hibernate.dialect.MySQLDialect
 52 #hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect
 53 #hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect
 54 #hibernate.connection.driver_class com.mysql.jdbc.Driver
 55 #hibernate.connection.url jdbc:mysql:///test
 56 #hibernate.connection.username gavin
 57 #hibernate.connection.password
 58 
 59 
 60 ## Oracle
 61 
 62 #hibernate.dialect org.hibernate.dialect.Oracle8iDialect
 63 #hibernate.dialect org.hibernate.dialect.Oracle9iDialect
 64 #hibernate.dialect org.hibernate.dialect.Oracle10gDialect
 65 #hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver
 66 #hibernate.connection.username ora
 67 #hibernate.connection.password ora
 68 #hibernate.connection.url jdbc:oracle:thin:@localhost:1521:orcl
 69 #hibernate.connection.url jdbc:oracle:thin:@localhost:1522:XE
 70 
 71 
 72 ## PostgreSQL
 73 
 74 #hibernate.dialect org.hibernate.dialect.PostgreSQLDialect
 75 #hibernate.connection.driver_class org.postgresql.Driver
 76 #hibernate.connection.url jdbc:postgresql:template1
 77 #hibernate.connection.username pg
 78 #hibernate.connection.password
 79 
 80 
 81 ## DB2
 82 
 83 #hibernate.dialect org.hibernate.dialect.DB2Dialect
 84 #hibernate.connection.driver_class com.ibm.db2.jcc.DB2Driver
 85 #hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver
 86 #hibernate.connection.url jdbc:db2://localhost:50000/somename
 87 #hibernate.connection.url jdbc:db2:somename
 88 #hibernate.connection.username db2
 89 #hibernate.connection.password db2
 90 
 91 ## TimesTen
 92 
 93 #hibernate.dialect org.hibernate.dialect.TimesTenDialect
 94 #hibernate.connection.driver_class com.timesten.jdbc.TimesTenDriver
 95 #hibernate.connection.url jdbc:timesten:direct:test
 96 #hibernate.connection.username
 97 #hibernate.connection.password 
 98 
 99 ## DB2/400
100 
101 #hibernate.dialect org.hibernate.dialect.DB2400Dialect
102 #hibernate.connection.username user
103 #hibernate.connection.password password
104 
105 ## Native driver
106 #hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver
107 #hibernate.connection.url jdbc:db2://systemname
108 
109 ## Toolbox driver
110 #hibernate.connection.driver_class com.ibm.as400.access.AS400JDBCDriver
111 #hibernate.connection.url jdbc:as400://systemname
112 
113 
114 ## Derby (not supported!)
115 
116 #hibernate.dialect org.hibernate.dialect.DerbyDialect
117 #hibernate.connection.driver_class org.apache.derby.jdbc.EmbeddedDriver
118 #hibernate.connection.username
119 #hibernate.connection.password
120 #hibernate.connection.url jdbc:derby:build/db/derby/hibernate;create=true
121 
122 
123 ## Sybase
124 
125 #hibernate.dialect org.hibernate.dialect.SybaseDialect
126 #hibernate.connection.driver_class com.sybase.jdbc2.jdbc.SybDriver
127 #hibernate.connection.username sa
128 #hibernate.connection.password sasasa
129 #hibernate.connection.url jdbc:sybase:Tds:co3061835-a:5000/tempdb
130 
131 
132 ## Mckoi SQL
133 
134 #hibernate.dialect org.hibernate.dialect.MckoiDialect
135 #hibernate.connection.driver_class com.mckoi.JDBCDriver
136 #hibernate.connection.url jdbc:mckoi:///
137 #hibernate.connection.url jdbc:mckoi:local://C:/mckoi1.0.3/db.conf
138 #hibernate.connection.username admin
139 #hibernate.connection.password nimda
140 
141 
142 ## SAP DB
143 
144 #hibernate.dialect org.hibernate.dialect.SAPDBDialect
145 #hibernate.connection.driver_class com.sap.dbtech.jdbc.DriverSapDB
146 #hibernate.connection.url jdbc:sapdb://localhost/TST
147 #hibernate.connection.username TEST
148 #hibernate.connection.password TEST
149 #hibernate.query.substitutions yes 'Y', no 'N'
150 
151 
152 ## MS SQL Server
153 
154 #hibernate.dialect org.hibernate.dialect.SQLServerDialect
155 #hibernate.connection.username sa
156 #hibernate.connection.password sa
157 
158 ## JSQL Driver
159 #hibernate.connection.driver_class com.jnetdirect.jsql.JSQLDriver
160 #hibernate.connection.url jdbc:JSQLConnect://1E1/test
161 
162 ## JTURBO Driver
163 #hibernate.connection.driver_class com.newatlanta.jturbo.driver.Driver
164 #hibernate.connection.url jdbc:JTurbo://1E1:1433/test
165 
166 ## WebLogic Driver
167 #hibernate.connection.driver_class weblogic.jdbc.mssqlserver4.Driver
168 #hibernate.connection.url jdbc:weblogic:mssqlserver4:1E1:1433
169 
170 ## Microsoft Driver (not recommended!)
171 #hibernate.connection.driver_class com.microsoft.jdbc.sqlserver.SQLServerDriver
172 #hibernate.connection.url jdbc:microsoft:sqlserver://1E1;DatabaseName=test;SelectMethod=cursor
173 
174 ## The New Microsoft Driver 
175 #hibernate.connection.driver_class com.microsoft.sqlserver.jdbc.SQLServerDriver
176 #hibernate.connection.url jdbc:sqlserver://localhost
177 
178 ## jTDS (since version 0.9)
179 #hibernate.connection.driver_class net.sourceforge.jtds.jdbc.Driver
180 #hibernate.connection.url jdbc:jtds:sqlserver://1E1/test
181 
182 ## Interbase
183 
184 #hibernate.dialect org.hibernate.dialect.InterbaseDialect
185 #hibernate.connection.username sysdba
186 #hibernate.connection.password masterkey
187 
188 ## DO NOT specify hibernate.connection.sqlDialect
189 
190 ## InterClient
191 
192 #hibernate.connection.driver_class interbase.interclient.Driver
193 #hibernate.connection.url jdbc:interbase://localhost:3060/C:/firebird/test.gdb
194 
195 ## Pure Java
196 
197 #hibernate.connection.driver_class org.firebirdsql.jdbc.FBDriver
198 #hibernate.connection.url jdbc:firebirdsql:localhost/3050:/firebird/test.gdb
199 
200 
201 ## Pointbase
202 
203 #hibernate.dialect org.hibernate.dialect.PointbaseDialect
204 #hibernate.connection.driver_class com.pointbase.jdbc.jdbcUniversalDriver
205 #hibernate.connection.url jdbc:pointbase:embedded:sample
206 #hibernate.connection.username PBPUBLIC
207 #hibernate.connection.password PBPUBLIC
208 
209 
210 ## Ingres
211 
212 ## older versions (before Ingress 2006)
213 
214 #hibernate.dialect org.hibernate.dialect.IngresDialect
215 #hibernate.connection.driver_class ca.edbc.jdbc.EdbcDriver
216 #hibernate.connection.url jdbc:edbc://localhost:II7/database
217 #hibernate.connection.username user
218 #hibernate.connection.password password
219 
220 ## Ingres 2006 or later
221 
222 #hibernate.dialect org.hibernate.dialect.IngresDialect
223 #hibernate.connection.driver_class com.ingres.jdbc.IngresDriver
224 #hibernate.connection.url jdbc:ingres://localhost:II7/database;CURSOR=READONLY;auto=multi
225 #hibernate.connection.username user
226 #hibernate.connection.password password
227 
228 ## Mimer SQL
229 
230 #hibernate.dialect org.hibernate.dialect.MimerSQLDialect
231 #hibernate.connection.driver_class com.mimer.jdbc.Driver
232 #hibernate.connection.url jdbc:mimer:multi1
233 #hibernate.connection.username hibernate
234 #hibernate.connection.password hibernate
235 
236 
237 ## InterSystems Cache
238 
239 #hibernate.dialect org.hibernate.dialect.Cache71Dialect
240 #hibernate.connection.driver_class com.intersys.jdbc.CacheDriver
241 #hibernate.connection.username _SYSTEM
242 #hibernate.connection.password SYS
243 #hibernate.connection.url jdbc:Cache://127.0.0.1:1972/HIBERNATE
244 
245 
246 #################################
247 ### Hibernate Connection Pool ###
248 #################################
249 
250 hibernate.connection.pool_size 1
251 
252 
253 
254 ###########################
255 ### C3P0 Connection Pool###
256 ###########################
257 
258 #hibernate.c3p0.max_size 2
259 #hibernate.c3p0.min_size 2
260 #hibernate.c3p0.timeout 5000
261 #hibernate.c3p0.max_statements 100
262 #hibernate.c3p0.idle_test_period 3000
263 #hibernate.c3p0.acquire_increment 2
264 #hibernate.c3p0.validate false
265 
266 
267 
268 ##############################
269 ### Proxool Connection Pool###
270 ##############################
271 
272 ## Properties for external configuration of Proxool
273 
274 hibernate.proxool.pool_alias pool1
275 
276 ## Only need one of the following
277 
278 #hibernate.proxool.existing_pool true
279 #hibernate.proxool.xml proxool.xml
280 #hibernate.proxool.properties proxool.properties
281 
282 
283 
284 #################################
285 ### Plugin ConnectionProvider ###
286 #################################
287 
288 ## use a custom ConnectionProvider (if not set, Hibernate will choose a built-in ConnectionProvider using hueristics)
289 
290 #hibernate.connection.provider_class org.hibernate.connection.DriverManagerConnectionProvider
291 #hibernate.connection.provider_class org.hibernate.connection.DatasourceConnectionProvider
292 #hibernate.connection.provider_class org.hibernate.connection.C3P0ConnectionProvider
293 #hibernate.connection.provider_class org.hibernate.connection.ProxoolConnectionProvider
294 
295 
296 
297 #######################
298 ### Transaction API ###
299 #######################
300 
301 ## Enable automatic flush during the JTA beforeCompletion() callback
302 ## (This setting is relevant with or without the Transaction API)
303 
304 #hibernate.transaction.flush_before_completion
305 
306 
307 ## Enable automatic session close at the end of transaction
308 ## (This setting is relevant with or without the Transaction API)
309 
310 #hibernate.transaction.auto_close_session
311 
312 
313 ## the Transaction API abstracts application code from the underlying JTA or JDBC transactions
314 
315 #hibernate.transaction.factory_class org.hibernate.transaction.JTATransactionFactory
316 #hibernate.transaction.factory_class org.hibernate.transaction.JDBCTransactionFactory
317 
318 
319 ## to use JTATransactionFactory, Hibernate must be able to locate the UserTransaction in JNDI
320 ## default is java:comp/UserTransaction
321 ## you do NOT need this setting if you specify hibernate.transaction.manager_lookup_class
322 
323 #jta.UserTransaction jta/usertransaction
324 #jta.UserTransaction javax.transaction.UserTransaction
325 #jta.UserTransaction UserTransaction
326 
327 
328 ## to use the second-level cache with JTA, Hibernate must be able to obtain the JTA TransactionManager
329 
330 #hibernate.transaction.manager_lookup_class org.hibernate.transaction.JBossTransactionManagerLookup
331 #hibernate.transaction.manager_lookup_class org.hibernate.transaction.WeblogicTransactionManagerLookup
332 #hibernate.transaction.manager_lookup_class org.hibernate.transaction.WebSphereTransactionManagerLookup
333 #hibernate.transaction.manager_lookup_class org.hibernate.transaction.OrionTransactionManagerLookup
334 #hibernate.transaction.manager_lookup_class org.hibernate.transaction.ResinTransactionManagerLookup
335 
336 
337 
338 ##############################
339 ### Miscellaneous Settings ###
340 ##############################
341 
342 ## print all generated SQL to the console
343 
344 #hibernate.show_sql true
345 
346 
347 ## format SQL in log and console
348 
349 hibernate.format_sql true
350 
351 
352 ## add comments to the generated SQL
353 
354 #hibernate.use_sql_comments true
355 
356 
357 ## generate statistics
358 
359 #hibernate.generate_statistics true
360 
361 
362 ## auto schema export
363 
364 #hibernate.hbm2ddl.auto create-drop
365 #hibernate.hbm2ddl.auto create
366 #hibernate.hbm2ddl.auto update
367 #hibernate.hbm2ddl.auto validate
368 
369 
370 ## specify a default schema and catalog for unqualified tablenames
371 
372 #hibernate.default_schema test
373 #hibernate.default_catalog test
374 
375 
376 ## enable ordering of SQL UPDATEs by primary key
377 
378 #hibernate.order_updates true
379 
380 
381 ## set the maximum depth of the outer join fetch tree
382 
383 hibernate.max_fetch_depth 1
384 
385 
386 ## set the default batch size for batch fetching
387 
388 #hibernate.default_batch_fetch_size 8
389 
390 
391 ## rollback generated identifier values of deleted entities to default values
392 
393 #hibernate.use_identifer_rollback true
394 
395 
396 ## enable bytecode reflection optimizer (disabled by default)
397 
398 #hibernate.bytecode.use_reflection_optimizer true
399 
400 
401 
402 #####################
403 ### JDBC Settings ###
404 #####################
405 
406 ## specify a JDBC isolation level
407 
408 #hibernate.connection.isolation 4
409 
410 
411 ## enable JDBC autocommit (not recommended!)
412 
413 #hibernate.connection.autocommit true
414 
415 
416 ## set the JDBC fetch size
417 
418 #hibernate.jdbc.fetch_size 25
419 
420 
421 ## set the maximum JDBC 2 batch size (a nonzero value enables batching)
422 
423 #hibernate.jdbc.batch_size 5
424 #hibernate.jdbc.batch_size 0
425 
426 
427 ## enable batch updates even for versioned data
428 
429 hibernate.jdbc.batch_versioned_data true
430 
431 
432 ## enable use of JDBC 2 scrollable ResultSets (specifying a Dialect will cause Hibernate to use a sensible default)
433 
434 #hibernate.jdbc.use_scrollable_resultset true
435 
436 
437 ## use streams when writing binary types to / from JDBC
438 
439 hibernate.jdbc.use_streams_for_binary true
440 
441 
442 ## use JDBC 3 PreparedStatement.getGeneratedKeys() to get the identifier of an inserted row
443 
444 #hibernate.jdbc.use_get_generated_keys false
445 
446 
447 ## choose a custom JDBC batcher
448 
449 # hibernate.jdbc.factory_class
450 
451 
452 ## enable JDBC result set column alias caching 
453 ## (minor performance enhancement for broken JDBC drivers)
454 
455 # hibernate.jdbc.wrap_result_sets
456 
457 
458 ## choose a custom SQL exception converter
459 
460 #hibernate.jdbc.sql_exception_converter
461 
462 
463 
464 ##########################
465 ### Second-level Cache ###
466 ##########################
467 
468 ## optimize chache for minimal "puts" instead of minimal "gets" (good for clustered cache)
469 
470 #hibernate.cache.use_minimal_puts true
471 
472 
473 ## set a prefix for cache region names
474 
475 hibernate.cache.region_prefix hibernate.test
476 
477 
478 ## disable the second-level cache
479 
480 #hibernate.cache.use_second_level_cache false
481 
482 
483 ## enable the query cache
484 
485 #hibernate.cache.use_query_cache true
486 
487 
488 ## store the second-level cache entries in a more human-friendly format
489 
490 #hibernate.cache.use_structured_entries true
491 
492 
493 ## choose a cache implementation
494 
495 #hibernate.cache.provider_class org.hibernate.cache.EhCacheProvider
496 #hibernate.cache.provider_class org.hibernate.cache.EmptyCacheProvider
497 hibernate.cache.provider_class org.hibernate.cache.HashtableCacheProvider
498 #hibernate.cache.provider_class org.hibernate.cache.TreeCacheProvider
499 #hibernate.cache.provider_class org.hibernate.cache.OSCacheProvider
500 #hibernate.cache.provider_class org.hibernate.cache.SwarmCacheProvider
501 
502 
503 ## choose a custom query cache implementation
504 
505 #hibernate.cache.query_cache_factory
506 
507 
508 
509 ############
510 ### JNDI ###
511 ############
512 
513 ## specify a JNDI name for the SessionFactory
514 
515 #hibernate.session_factory_name hibernate/session_factory
516 
517 
518 ## Hibernate uses JNDI to bind a name to a SessionFactory and to look up the JTA UserTransaction;
519 ## if hibernate.jndi.* are not specified, Hibernate will use the default InitialContext() which
520 ## is the best approach in an application server
521 
522 #file system
523 #hibernate.jndi.class com.sun.jndi.fscontext.RefFSContextFactory
524 #hibernate.jndi.url file:/
525 
526 #WebSphere
527 #hibernate.jndi.class com.ibm.websphere.naming.WsnInitialContextFactory
528 #hibernate.jndi.url iiop://localhost:900/
hibernate.properties
原文地址:https://www.cnblogs.com/soficircle/p/7073914.html