1.0 Hibernate框架学习路线
- Hibernate入门
包括Hibernate的环境搭建、Hibernate的API、Hibernate的CRUD(增删查改)。- Hibernate的一级缓存、其他API
- Hibernate的一对多的配置、Hibernate的多对多的配置
- Hibernate的查询方式、抓取策略
2.0 CRM的案例
案例需求:
2.1 什么是CRM
CRM(Customer Relationship Management)客户关系管理。是利用相应的信息技术以及互联网技术来协调企业与顾客间在销售营、销和服务上的交互,向客户提交创新式的个性化客户交互和服务的过程。其最终目标是将客户的各项信息和活动集成起来。组建一个以客户为中心的企业,实现对面向客户的活动的全面管理。
2.2 CRM有哪些模块
3.0 Hibernate框架的概述
3.1 什么是框架
框架:指的是软件的半成品,已经完成了部分功能。
3.2 EE的经典三层结构
3.3 什么是Hibernate
Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,它将POJO与数据库表建立映射关系,是一个全自动的orm框架,hibernate可以自动生成SQL语句,自动执行,使得Java程序员可以随心所欲的使用对象编程思维来操纵数据库。 Hibernate可以应用在任何使用JDBC的场合,既可以在Java的客户端程序使用,也可以在Servlet/JSP的Web应用中使用,最具革命意义的是,Hibernate可以在应用EJB的JaveEE架构中取代CMP,完成数据持久化的重任。
或者说,Hibernate是一个持久层的ORM框架。
Hibernate可以在Java项目中使用,也可以在Web项目中使用。
3.3 什么是ORM
ORM:Object Relational Mapping(对象关系映射)。指的是将一个Java中的对象与关系型数据库中的表建立一种映射关系,从而操作对象就可以操作数据库中的表。
3.4 为什么要学习Hibernate
4.0 Hibernate的入门
4.1 下载Hibernate的开发环境
Hibernate官网下载点击此处,如下图箭头所示:
中文是这样的:
当下我的下载版本为hibernate-release-5.3.15.Final。解压:
或者在另一个官网下载:Hibernate
按图片指示步骤下载,版本为最新稳定版5.4.10(目前所装java jdk版本为jdk8):
到这一步等待片刻即可自动下载。
目录名称 | 说明 |
---|---|
docs | Hibernate开发的文档 |
lib | :Hibernate开发包 |
lib/required | :Hibernate开发的必须的依赖包 |
lib/optional | :Hibernate开发的可选的jar包 |
project | :Hibernate提供的项目 |
4.2 下一步,创建一个项目,引入jar包
数据库驱动包
Hibernate开发的必须的jar包
Hibernate引入日志记录包
在lib文件下放入需要配置的jar包:
5.3.15版本:
5.4.10版本:
首先,hibernate必须的包全选,放入lib中:
log4j等日志jar包:
下载Apache Log4j 2官网
简单的Java日志Facade (SLF4J)官网
三个链接随便点击哪个都行,只需要下载其中一个,下载下来后,解压再解压,直到看到jar包。
无其他要求,分别下载最新版本的api和log4j包即可。
最后需要的:
所有jar包目录:
jar导入项目:
看到如下“酒瓶子”就表示导入完成:
4.3 创建数据库表
围绕本文开头的CRM案例建数据表,建表语句如下:
CREATE TABLE `cst_customer` (
`cust_id` bigint(32) NOT NULL AUTO_INCREMENT COMMENT '客户编号(主键)',
`cust_name` varchar(32) NOT NULL COMMENT '客户名称(公司名称)',
`cust_source` varchar(32) DEFAULT NULL COMMENT '客户信息来源',
`cust_industry` varchar(32) DEFAULT NULL COMMENT '客户所属行业',
`cust_level` varchar(32) DEFAULT NULL COMMENT '客户级别',
`cust_phone` varchar(64) DEFAULT NULL COMMENT '固定电话',
`cust_mobile` varchar(16) DEFAULT NULL COMMENT '移动电话',
PRIMARY KEY (`cust_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
打开数据库图形化操作软件,我用的是Navicat Premium 12。
新建一个叫hibernate_learn的数据库。
点击“查询”、“新建查询”、复制粘贴sql语句,点击“运行”。
此时,查看表,可以看到新建数据库表成功。
4.3 创建实例类
代码如下:
package com.edp.learn;
/**
* 客户管理实体类
*
* @author EDPeng CREATE TABLE `cst_customer` ( `cust_id` bigint(32) NOT NULL
* AUTO_INCREMENT COMMENT '客户编号(主键)', `cust_name` varchar(32) NOT NULL
* COMMENT '客户名称(公司名称)', `cust_source` varchar(32) DEFAULT NULL COMMENT
* '客户信息来源', `cust_industry` varchar(32) DEFAULT NULL COMMENT '客户所属行业',
* `cust_level` varchar(32) DEFAULT NULL COMMENT '客户级别', `cust_phone`
* varchar(64) DEFAULT NULL COMMENT '固定电话', `cust_mobile` varchar(16)
* DEFAULT NULL COMMENT '移动电话', PRIMARY KEY (`cust_id`) ) ENGINE=InnoDB
* AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
*/
public class Customer {
private Long cust_id;//客户id
private String cust_name;//客户的名称
private String cust_source;//客户的来源
private String cust_industry;//客户所属行业
private String cust_level;//客户的级别
private String cust_phone;//客户的固定电话
private String cust_mobile;//客户的移动电话
public Long getCust_id() {
return cust_id;
}
public void setCust_id(Long cust_id) {
this.cust_id = cust_id;
}
public String getCust_name() {
return cust_name;
}
public void setCust_name(String cust_name) {
this.cust_name = cust_name;
}
public String getCust_source() {
return cust_source;
}
public void setCust_source(String cust_source) {
this.cust_source = cust_source;
}
public String getCust_industry() {
return cust_industry;
}
public void setCust_industry(String cust_industry) {
this.cust_industry = cust_industry;
}
public String getCust_level() {
return cust_level;
}
public void setCust_level(String cust_level) {
this.cust_level = cust_level;
}
public String getCust_phone() {
return cust_phone;
}
public void setCust_phone(String cust_phone) {
this.cust_phone = cust_phone;
}
public String getCust_mobile() {
return cust_mobile;
}
public void setCust_mobile(String cust_mobile) {
this.cust_mobile = cust_mobile;
}
@Override
public String toString() {
return "Customer [cust_id=" + cust_id + ", cust_name=" + cust_name + ", cust_source=" + cust_source
+ ", cust_industry=" + cust_industry + ", cust_level=" + cust_level + ", cust_phone=" + cust_phone
+ ", cust_mobile=" + cust_mobile + "]";
}
}
4.4 创建映射
映射需要通过XML的配置文件来完成,这个配置文件可以任意命名。尽量统一命名规范(类名.hbm.xml)。
新建一个XML文件:
文件结构如下所示。
一般的xml文件都有约束。那这个的约束怎么设置?我们双击打开加入的hibernate-care的jar包。
打开第一个org.hibernate包中的hibernate-mapping-3.0.dtd文件。
将开头注释中的框内的内容复制粘贴到XML文件中,约束就设置好了,可以写内容。
此时输入“<”符号,Eclipse就会有相应的词法提示。
编辑XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!-- hibernate-mapping是根标签 -->
<!-- 建立类与表的映射 -->
<class name="com.edp.learn.Customer" table="cst_customer"></class>
<!-- name:哪个类,全路径,table:哪个表 -->
</hibernate-mapping>
把类的全路径复制粘贴到XML文件中去。
进入数据库,把数据库中的表名复制粘贴到XML文件中。
这样我们就建立好了类和表的映射。
可以看到此处有一个class报错。是因为com.edp.learn.Customer类里面有一些属性,和cst_customer表里面的一些字段也得建立对应关系。而且有一个非常特殊的对应属性“cust_id”,他得和表里面的组件进行对应。代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!-- hibernate-mapping是根标签 -->
<!-- 建立类与表的映射 -->
<class name="com.edp.learn.Customer" table="cst_customer">
<!-- name:哪个类,全路径,table:哪个表 -->
<!-- Id:建立类中的属性与表中的主键对应 -->
<id name="cust_id" column="cust_id">
<!-- name:在类中的名字 column:表中的字段;此处为一样的名称 -->
<generator class="native" />
<!-- 组件都有一种生成策略,此处使用一种本地策略。 -->
</id>
</class>
</hibernate-mapping>
其中id中的属性来源如下:
name:在类中的名字 column:数据库表中的字段;此处为一样的名称
然后设置类中的普通属性和表的字段的对应。至此,完整代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!-- hibernate-mapping是根标签 -->
<!-- 建立类与表的映射 -->
<class name="com.edp.learn.Customer" table="cst_customer">
<!-- name:哪个类,全路径,table:哪个表 -->
<!-- Id:建立类中的属性与表中的主键对应 -->
<id name="cust_id" column="cust_id">
<!-- name:在类中的名字 column:表中的字段;此处为一样的名称 -->
<generator class="native" />
<!-- 组件都有一种生成策略,此处使用一种本地策略。 -->
</id>
<!-- 建立类中的普通属性和表的字段的对应 -->
<!-- 除了主键以外的属性,都用property -->
<property name="cust_name" column="cust_name" />
<!-- 客户的名称 -->
<property name="cust_source" column="cust_source" />
<!-- 客户的来源 -->
<property name="cust_industry" column="cust_industry" />
<!-- 客户所属行业 -->
<property name="cust_level" column="cust_level" />
<!-- 客户的级别 -->
<property name="cust_phone" column="cust_phone" />
<!-- 客户的固定电话 -->
<property name="cust_mobile" column="cust_mobile" />
<!-- 客户的移动电话 -->
</class>
</hibernate-mapping>
4.5 创建一个Hibernate的核心配置文件
Hibernate的核心配置文件的名称:hibernate.cfg.xml
但是,这里要在src目录下新建一个XML文件。
建好如下所示:
约束在hibernate-core-5.2.11.Final.jar包中org.hibernate目录包下的hibernate-configuration-3.0.dtd文件中。
XML文件约束如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
此时需要在根标签下配置session-factory,里面配置连接哪个数据库,使用哪个驱动,用户名、密码等。
这时候需要写一个property标签,并设置属性,其中具体的属性名在hibernate解压文件的案例中有,在project/etc文件夹下的hibernate.properties中,在本文最后附上全文。此处仅放连接MySQL的提示,里面有连接各种数据库的基本的参数。
## MySQL
#hibernate.dialect org.hibernate.dialect.MySQLDialect
#hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect
#hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect
#hibernate.connection.driver_class com.mysql.jdbc.Driver
#hibernate.connection.url jdbc:mysql:///test
#hibernate.connection.username gavin
#hibernate.connection.password
XML文件设置如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<!-- 根标签 -->
<session-factory>
<!-- 连接数据库的基本参数 -->
<!-- 配置数据库驱动 -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- 配置数据库连接URL -->
<property name="hibernate.connection.url">jdbc:mysql:///hibernate_learn</property>
<!-- jdbc:mysql://localhost:3306/hibernate_learn连接本地库可以省略,所以这里用/// -->
<!-- 数据库user -->
<property name="hibernate.connection.username">root</property>
<!-- 数据库user密码 -->
<property name="hibernate.connection.password">自己的MySQL登录密码</property>
<!-- 配置hibernate的方言 告诉hibernate要识别MySQL的“方言”(这样,hibernate就能帮开发者生成MySQL识别的SQL语句) -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- name="hibernate.dialect":表示Hibernate的方言就是MySQL -->
<!-- 告诉核心配置文件,我要加载哪个映射 -->
<mapping resource="com/edp/learn/Customer.hbm.xml"></mapping>
</session-factory>
</hibernate-configuration>
以上内容为必须配置的内容,其他内容为选设。
4.6 Hibernate的核心配置文件部分选设
<!-- 可选配置 -->
<!-- 打印SQL语句 -->
<property name="hibernate.show_sql">true</property>
<!-- 格式化SQL,使SQL语句在打印的时候更加漂亮 -->
<property name="hibernate.format_sql">true</property>
此时的完整代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<!-- 根标签 -->
<session-factory>
<!-- 连接数据库的基本参数。 -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql:///hibernate_learn</property>
<!-- jdbc:mysql://localhost:3306/hibernate_learn连接本地库可以省略,所以这里用/// -->
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">**********</property>
<!-- 配置hibernate的方言 告诉hibernate要识别MySQL的“方言”(这样,hibernate就能帮开发者生成MySQL识别的SQL语句) -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- name="hibernate.dialect":表示Hibernate的方言就是MySQL -->
<!-- 可选配置 -->
<!-- 打印SQL语句 -->
<property name="hibernate.show_sql">true</property>
<!-- 格式化SQL,使SQL语句在打印的时候更加漂亮 -->
<property name="hibernate.format_sql">true</property>
<!-- 告诉核心配置文件,我要加载哪个映射 -->
<mapping resource="com/edp/learn/Customer.hbm.xml"></mapping>
</session-factory>
</hibernate-configuration>
最后Eclipse展示效果如下:
5.0 附录
附上hibernate官方演示配置数据库连接的参考文档:
#
# Hibernate, Relational Persistence for Idiomatic Java
#
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
#
######################
### Query Language ###
######################
## define query language constants / function names
hibernate.query.substitutions yes 'Y', no 'N'
## select the classic query parser
#hibernate.query.factory_class org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory
#################
### Platforms ###
#################
## JNDI Datasource
#hibernate.connection.datasource jdbc/test
#hibernate.connection.username db2
#hibernate.connection.password db2
## HypersonicSQL
hibernate.dialect org.hibernate.dialect.HSQLDialect
hibernate.connection.driver_class org.hsqldb.jdbcDriver
hibernate.connection.username sa
hibernate.connection.password
hibernate.connection.url jdbc:hsqldb:./build/db/hsqldb/hibernate
#hibernate.connection.url jdbc:hsqldb:hsql://localhost
#hibernate.connection.url jdbc:hsqldb:test
## H2 (www.h2database.com)
#hibernate.dialect org.hibernate.dialect.H2Dialect
#hibernate.connection.driver_class org.h2.Driver
#hibernate.connection.username sa
#hibernate.connection.password
#hibernate.connection.url jdbc:h2:mem:./build/db/h2/hibernate
#hibernate.connection.url jdbc:h2:testdb/h2test
#hibernate.connection.url jdbc:h2:mem:imdb1
#hibernate.connection.url jdbc:h2:tcp://dbserv:8084/sample;
#hibernate.connection.url jdbc:h2:ssl://secureserv:8085/sample;
#hibernate.connection.url jdbc:h2:ssl://secureserv/testdb;cipher=AES
## MySQL
#hibernate.dialect org.hibernate.dialect.MySQLDialect
#hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect
#hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect
#hibernate.connection.driver_class com.mysql.jdbc.Driver
#hibernate.connection.url jdbc:mysql:///test
#hibernate.connection.username gavin
#hibernate.connection.password
## Oracle
#hibernate.dialect org.hibernate.dialect.Oracle8iDialect
#hibernate.dialect org.hibernate.dialect.Oracle9iDialect
#hibernate.dialect org.hibernate.dialect.Oracle10gDialect
#hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver
#hibernate.connection.username ora
#hibernate.connection.password ora
#hibernate.connection.url jdbc:oracle:thin:@localhost:1521:orcl
#hibernate.connection.url jdbc:oracle:thin:@localhost:1522:XE
## PostgreSQL
#hibernate.dialect org.hibernate.dialect.PostgreSQLDialect
#hibernate.connection.driver_class org.postgresql.Driver
#hibernate.connection.url jdbc:postgresql:template1
#hibernate.connection.username pg
#hibernate.connection.password
## DB2
#hibernate.dialect org.hibernate.dialect.DB2Dialect
#hibernate.connection.driver_class com.ibm.db2.jcc.DB2Driver
#hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver
#hibernate.connection.url jdbc:db2://localhost:50000/somename
#hibernate.connection.url jdbc:db2:somename
#hibernate.connection.username db2
#hibernate.connection.password db2
## TimesTen
#hibernate.dialect org.hibernate.dialect.TimesTenDialect
#hibernate.connection.driver_class com.timesten.jdbc.TimesTenDriver
#hibernate.connection.url jdbc:timesten:direct:test
#hibernate.connection.username
#hibernate.connection.password
## DB2/400
#hibernate.dialect org.hibernate.dialect.DB2400Dialect
#hibernate.connection.username user
#hibernate.connection.password password
## Native driver
#hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver
#hibernate.connection.url jdbc:db2://systemname
## Toolbox driver
#hibernate.connection.driver_class com.ibm.as400.access.AS400JDBCDriver
#hibernate.connection.url jdbc:as400://systemname
## Derby (not supported!)
#hibernate.dialect org.hibernate.dialect.DerbyDialect
#hibernate.connection.driver_class org.apache.derby.jdbc.EmbeddedDriver
#hibernate.connection.username
#hibernate.connection.password
#hibernate.connection.url jdbc:derby:build/db/derby/hibernate;create=true
## Sybase
#hibernate.dialect org.hibernate.dialect.SybaseDialect
#hibernate.connection.driver_class com.sybase.jdbc2.jdbc.SybDriver
#hibernate.connection.username sa
#hibernate.connection.password sasasa
#hibernate.connection.url jdbc:sybase:Tds:co3061835-a:5000/tempdb
## Mckoi SQL
#hibernate.dialect org.hibernate.dialect.MckoiDialect
#hibernate.connection.driver_class com.mckoi.JDBCDriver
#hibernate.connection.url jdbc:mckoi:///
#hibernate.connection.url jdbc:mckoi:local://C:/mckoi1.0.3/db.conf
#hibernate.connection.username admin
#hibernate.connection.password nimda
## SAP DB
#hibernate.dialect org.hibernate.dialect.SAPDBDialect
#hibernate.connection.driver_class com.sap.dbtech.jdbc.DriverSapDB
#hibernate.connection.url jdbc:sapdb://localhost/TST
#hibernate.connection.username TEST
#hibernate.connection.password TEST
#hibernate.query.substitutions yes 'Y', no 'N'
## MS SQL Server
#hibernate.dialect org.hibernate.dialect.SQLServerDialect
#hibernate.connection.username sa
#hibernate.connection.password sa
## JSQL Driver
#hibernate.connection.driver_class com.jnetdirect.jsql.JSQLDriver
#hibernate.connection.url jdbc:JSQLConnect://1E1/test
## JTURBO Driver
#hibernate.connection.driver_class com.newatlanta.jturbo.driver.Driver
#hibernate.connection.url jdbc:JTurbo://1E1:1433/test
## WebLogic Driver
#hibernate.connection.driver_class weblogic.jdbc.mssqlserver4.Driver
#hibernate.connection.url jdbc:weblogic:mssqlserver4:1E1:1433
## Microsoft Driver (not recommended!)
#hibernate.connection.driver_class com.microsoft.jdbc.sqlserver.SQLServerDriver
#hibernate.connection.url jdbc:microsoft:sqlserver://1E1;DatabaseName=test;SelectMethod=cursor
## The New Microsoft Driver
#hibernate.connection.driver_class com.microsoft.sqlserver.jdbc.SQLServerDriver
#hibernate.connection.url jdbc:sqlserver://localhost
## jTDS (since version 0.9)
#hibernate.connection.driver_class net.sourceforge.jtds.jdbc.Driver
#hibernate.connection.url jdbc:jtds:sqlserver://1E1/test
## Interbase
#hibernate.dialect org.hibernate.dialect.InterbaseDialect
#hibernate.connection.username sysdba
#hibernate.connection.password masterkey
## DO NOT specify hibernate.connection.sqlDialect
## InterClient
#hibernate.connection.driver_class interbase.interclient.Driver
#hibernate.connection.url jdbc:interbase://localhost:3060/C:/firebird/test.gdb
## Pure Java
#hibernate.connection.driver_class org.firebirdsql.jdbc.FBDriver
#hibernate.connection.url jdbc:firebirdsql:localhost/3050:/firebird/test.gdb
## Pointbase
#hibernate.dialect org.hibernate.dialect.PointbaseDialect
#hibernate.connection.driver_class com.pointbase.jdbc.jdbcUniversalDriver
#hibernate.connection.url jdbc:pointbase:embedded:sample
#hibernate.connection.username PBPUBLIC
#hibernate.connection.password PBPUBLIC
## Ingres
## older versions (before Ingress 2006)
#hibernate.dialect org.hibernate.dialect.IngresDialect
#hibernate.connection.driver_class ca.edbc.jdbc.EdbcDriver
#hibernate.connection.url jdbc:edbc://localhost:II7/database
#hibernate.connection.username user
#hibernate.connection.password password
## Ingres 2006 or later
#hibernate.dialect org.hibernate.dialect.IngresDialect
#hibernate.connection.driver_class com.ingres.jdbc.IngresDriver
#hibernate.connection.url jdbc:ingres://localhost:II7/database;CURSOR=READONLY;auto=multi
#hibernate.connection.username user
#hibernate.connection.password password
## Mimer SQL
#hibernate.dialect org.hibernate.dialect.MimerSQLDialect
#hibernate.connection.driver_class com.mimer.jdbc.Driver
#hibernate.connection.url jdbc:mimer:multi1
#hibernate.connection.username hibernate
#hibernate.connection.password hibernate
## InterSystems Cache
#hibernate.dialect org.hibernate.dialect.Cache71Dialect
#hibernate.connection.driver_class com.intersys.jdbc.CacheDriver
#hibernate.connection.username _SYSTEM
#hibernate.connection.password SYS
#hibernate.connection.url jdbc:Cache://127.0.0.1:1972/HIBERNATE
#################################
### Hibernate Connection Pool ###
#################################
hibernate.connection.pool_size 1
###########################
### C3P0 Connection Pool###
###########################
#hibernate.c3p0.max_size 2
#hibernate.c3p0.min_size 2
#hibernate.c3p0.timeout 5000
#hibernate.c3p0.max_statements 100
#hibernate.c3p0.idle_test_period 3000
#hibernate.c3p0.acquire_increment 2
#hibernate.c3p0.validate false
##############################
### Proxool Connection Pool###
##############################
## Properties for external configuration of Proxool
hibernate.proxool.pool_alias pool1
## Only need one of the following
#hibernate.proxool.existing_pool true
#hibernate.proxool.xml proxool.xml
#hibernate.proxool.properties proxool.properties
#################################
### Plugin ConnectionProvider ###
#################################
## use a custom ConnectionProvider (if not set, Hibernate will choose a built-in ConnectionProvider using hueristics)
#hibernate.connection.provider_class org.hibernate.connection.DriverManagerConnectionProvider
#hibernate.connection.provider_class org.hibernate.connection.DatasourceConnectionProvider
#hibernate.connection.provider_class org.hibernate.connection.C3P0ConnectionProvider
#hibernate.connection.provider_class org.hibernate.connection.ProxoolConnectionProvider
#######################
### Transaction API ###
#######################
## Enable automatic flush during the JTA beforeCompletion() callback
## (This setting is relevant with or without the Transaction API)
#hibernate.transaction.flush_before_completion
## Enable automatic session close at the end of transaction
## (This setting is relevant with or without the Transaction API)
#hibernate.transaction.auto_close_session
## the Transaction API abstracts application code from the underlying JTA or JDBC transactions
#hibernate.transaction.factory_class org.hibernate.transaction.JTATransactionFactory
#hibernate.transaction.factory_class org.hibernate.transaction.JDBCTransactionFactory
## to use JTATransactionFactory, Hibernate must be able to locate the UserTransaction in JNDI
## default is java:comp/UserTransaction
## you do NOT need this setting if you specify hibernate.transaction.manager_lookup_class
#jta.UserTransaction jta/usertransaction
#jta.UserTransaction javax.transaction.UserTransaction
#jta.UserTransaction UserTransaction
## to use the second-level cache with JTA, Hibernate must be able to obtain the JTA TransactionManager
#hibernate.transaction.manager_lookup_class org.hibernate.transaction.JBossTransactionManagerLookup
#hibernate.transaction.manager_lookup_class org.hibernate.transaction.WeblogicTransactionManagerLookup
#hibernate.transaction.manager_lookup_class org.hibernate.transaction.WebSphereTransactionManagerLookup
#hibernate.transaction.manager_lookup_class org.hibernate.transaction.OrionTransactionManagerLookup
#hibernate.transaction.manager_lookup_class org.hibernate.transaction.ResinTransactionManagerLookup
##############################
### Miscellaneous Settings ###
##############################
## print all generated SQL to the console
#hibernate.show_sql true
## format SQL in log and console
hibernate.format_sql true
## add comments to the generated SQL
#hibernate.use_sql_comments true
## generate statistics
#hibernate.generate_statistics true
## auto schema export
#hibernate.hbm2ddl.auto create-drop
#hibernate.hbm2ddl.auto create
#hibernate.hbm2ddl.auto update
#hibernate.hbm2ddl.auto validate
## specify a default schema and catalog for unqualified tablenames
#hibernate.default_schema test
#hibernate.default_catalog test
## enable ordering of SQL UPDATEs by primary key
#hibernate.order_updates true
## set the maximum depth of the outer join fetch tree
hibernate.max_fetch_depth 1
## set the default batch size for batch fetching
#hibernate.default_batch_fetch_size 8
## rollback generated identifier values of deleted entities to default values
#hibernate.use_identifier_rollback true
## enable bytecode reflection optimizer (disabled by default)
#hibernate.bytecode.use_reflection_optimizer true
#####################
### JDBC Settings ###
#####################
## specify a JDBC isolation level
#hibernate.connection.isolation 4
## enable JDBC autocommit (not recommended!)
#hibernate.connection.autocommit true
## set the JDBC fetch size
#hibernate.jdbc.fetch_size 25
## set the maximum JDBC 2 batch size (a nonzero value enables batching)
#hibernate.jdbc.batch_size 5
#hibernate.jdbc.batch_size 0
## enable batch updates even for versioned data
hibernate.jdbc.batch_versioned_data true
## enable use of JDBC 2 scrollable ResultSets (specifying a Dialect will cause Hibernate to use a sensible default)
#hibernate.jdbc.use_scrollable_resultset true
## use streams when writing binary types to / from JDBC
hibernate.jdbc.use_streams_for_binary true
## use JDBC 3 PreparedStatement.getGeneratedKeys() to get the identifier of an inserted row
#hibernate.jdbc.use_get_generated_keys false
## choose a custom JDBC batcher
# hibernate.jdbc.factory_class
## enable JDBC result set column alias caching
## (minor performance enhancement for broken JDBC drivers)
# hibernate.jdbc.wrap_result_sets
## choose a custom SQL exception converter
#hibernate.jdbc.sql_exception_converter
##########################
### Second-level Cache ###
##########################
## optimize cache for minimal "puts" instead of minimal "gets" (good for clustered cache)
#hibernate.cache.use_minimal_puts true
## set a prefix for cache region names
hibernate.cache.region_prefix hibernate.test
## disable the second-level cache
#hibernate.cache.use_second_level_cache false
## enable the query cache
#hibernate.cache.use_query_cache true
## store the second-level cache entries in a more human-friendly format
#hibernate.cache.use_structured_entries true
## choose a cache implementation
#hibernate.cache.region.factory_class org.hibernate.cache.infinispan.InfinispanRegionFactory
#hibernate.cache.region.factory_class org.hibernate.cache.infinispan.JndiInfinispanRegionFactory
#hibernate.cache.region.factory_class org.hibernate.cache.internal.EhCacheRegionFactory
#hibernate.cache.region.factory_class org.hibernate.cache.internal.SingletonEhCacheRegionFactory
hibernate.cache.region.factory_class org.hibernate.cache.internal.NoCachingRegionFactory
## choose a custom query cache implementation
#hibernate.cache.query_cache_factory
############
### JNDI ###
############
## specify a JNDI name for the SessionFactory
#hibernate.session_factory_name hibernate/session_factory
## Hibernate uses JNDI to bind a name to a SessionFactory and to look up the JTA UserTransaction;
## if hibernate.jndi.* are not specified, Hibernate will use the default InitialContext() which
## is the best approach in an application server
#file system
#hibernate.jndi.class com.sun.jndi.fscontext.RefFSContextFactory
#hibernate.jndi.url file:/
#WebSphere
#hibernate.jndi.class com.ibm.websphere.naming.WsnInitialContextFactory
#hibernate.jndi.url iiop://localhost:900/
END