【Java中级】5.0 SSH之Hibernate框架(一)——使用Hibernate完成CRM客户管理(上)...

1.0 Hibernate框架学习路线
  1. Hibernate入门
    包括Hibernate的环境搭建、Hibernate的API、Hibernate的CRUD(增删查改)。
  2. Hibernate的一级缓存、其他API
  3. Hibernate的一对多的配置、Hibernate的多对多的配置
  4. Hibernate的查询方式、抓取策略
2.0 CRM的案例

案例需求:


16102290-5caeaa3e6410571d.png
image.png
2.1 什么是CRM

CRM(Customer Relationship Management)客户关系管理。是利用相应的信息技术以及互联网技术来协调企业与顾客间在销售营、销和服务上的交互,向客户提交创新式的个性化客户交互和服务的过程。其最终目标是将客户的各项信息和活动集成起来。组建一个以客户为中心的企业,实现对面向客户的活动的全面管理。

2.2 CRM有哪些模块
16102290-127e4f95e629f16d.png
image.png

16102290-a2627958860e0355.png
image.png
3.0 Hibernate框架的概述
3.1 什么是框架

框架:指的是软件的半成品,已经完成了部分功能。

3.2 EE的经典三层结构
16102290-1ea84d978f097ba7.png
image.png
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中的对象与关系型数据库中的表建立一种映射关系,从而操作对象就可以操作数据库中的表。


16102290-618f5d2f4084c72f.png
image.png
3.4 为什么要学习Hibernate
16102290-d18ce07d8216a7a6.png
image.png
4.0 Hibernate的入门
4.1 下载Hibernate的开发环境

Hibernate官网下载点击此处,如下图箭头所示:

16102290-ad42f09b8afb9a5e.png
image.png

中文是这样的:
16102290-fb13ff2ff3fb041d.png
image.png

当下我的下载版本为hibernate-search-5.8.0.Final-dist。解压:


16102290-a306b1ba6853ae67.png
image.png
目录名称说明
docsHibernate开发的文档
dist:Hibernate开发包
dist/required:Hibernate开发的必须的依赖包
dist/optional:Hibernate开发的可选的jar包
project:Hibernate提供的项目
4.2 下一步,创建一个项目,引入jar包

数据库驱动包
Hibernate开发的必须的jar包
Hibernate引入日志记录包

16102290-8d73ca1567fb226b.png
image.png

在lib文件下放入需要配置的jar包:


16102290-aaa6c6649a49c35f.png
image.png

首先,hibernate必须的包全选,放入lib中:

16102290-efea24c0bc79ff67.png
image.png

log4j等日志jar包:
下载Apache Log4j 2官网
简单的Java日志Facade (SLF4J)官网
16102290-2425fb8ea1362f4a.png
image.png

三个链接随便点击哪个都行,只需要下载其中一个,下载下来后,解压再解压,直到看到jar包。
16102290-3229b7ca3eaa54e0.png
image.png

16102290-0e9cffe70f788ce7.png
image.png

16102290-763ead80a74dcd1b.png
image.png

无其他要求,分别下载最新版本的api和log4j包即可。


16102290-3e32707bbc5b87f1.png
image.png

最后需要的:


16102290-3d4752911aab5cef.png
image.png

所有jar包目录:
16102290-e3736c5b52ccbfd2.png
image.png

jar导入项目:


16102290-ed2f2ad56f143230.png
image.png

看到如下“酒瓶子”就表示导入完成:
16102290-3e587aeb763930d9.png
image.png
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。


16102290-48c114e22ccc8d1b.png
image.png

新建一个叫hibernate_learn的数据库。


16102290-4c4ae693305d8258.png
image.png

16102290-e226e0a7939e8c9b.png
image.png

点击“查询”、“新建查询”、复制粘贴sql语句,点击“运行”。
16102290-e5feab0662e7fd7c.png
image.png

16102290-8dfd97b07e08b8d9.png
image.png

16102290-44958350ef767a31.png
image.png

此时,查看表,可以看到新建数据库表成功。


16102290-4e56c51c01cf6621.png
image.png
4.3 创建实例类
16102290-b6ae6c814f6c6fa5.png
image.png

代码如下:

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文件:

16102290-1be22a54a9b0510c.png
image.png

16102290-805f768e1538ba80.png
image.png

16102290-fb29fc4944533cc2.png
image.png

文件结构如下所示。
16102290-f5911f8e340505ca.png
image.png

一般的xml文件都有约束。那这个的约束怎么设置?我们双击打开加入的hibernate-care的jar包。
16102290-00cefe651fbf4296.png
image.png

打开第一个org.hibernate包中的hibernate-mapping-3.0.dtd文件。
16102290-25ba6449e4b04add.png
image.png

将开头注释中的框内的内容复制粘贴到XML文件中,约束就设置好了,可以写内容。
16102290-905d564e1d31ba15.png
image.png

16102290-2e2d5eb2e046997a.png
image.png

此时输入 “<”符号,Eclipse就会有相应的词法提示。
16102290-a1868eab0ae45e53.png
image.png

编辑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文件中去。


16102290-aa7074b556009649.png
image.png

进入数据库,把数据库中的表名复制粘贴到XML文件中。

16102290-ad2453bb856f86bd.png
image.png

这样我们就建立好了类和表的映射。
16102290-25b306b979c456e4.png
image.png

可以看到此处有一个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:数据库表中的字段;此处为一样的名称

16102290-1c852bd455734463.png
image.png

16102290-88a2b61c04a1654a.png
image.png

然后设置类中的普通属性和表的字段的对应。至此,完整代码如下:

<?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文件。


16102290-74d18ae1301fdacc.png
image.png

建好如下所示:


16102290-d65296d5de847dbf.png
image.png

约束在hibernate-core-5.2.11.Final.jar包中org.hibernate目录包下的hibernate-configuration-3.0.dtd文件中。
16102290-24560e6908399584.png
image.png

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解压文件的案例中有,但是我用的hibernate-search-5.8.0.Final没找到,在本文最后附上全文。此处仅放连接MySQL的提示,l里面有连接各种数据库的基本的参数。

## 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>

以上内容为必须配置的内容,其他内容为选设,此处不做介绍。
最后Eclipse展示效果如下:


16102290-d459c23f75f25a23.png
image.png
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_identifer_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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值