现在这记性是越来越不如从前了,虽然从前也总是记不住。学一点东西就得重复练好几遍,如果十天半个月不用可能就又忘得一干二净了。还是写下来比较好。学完一点知识赶快总结一下。

Hibernate是JBoss公司的产品,主要应用ORM即对象关系映射,实现对象和关系进行映射的框架。实际的代码量并未减少,但是好多代码框架帮我们完成了,对于开发者来说要写的代码量就大大减少了。世面上的数据库产品,Hibernate基本都支持。

1.使用Hibernate连接数据库,可以是web工程,也可以是java工程

第一步拷包:建立一个工程,web或java的都行。如果是web的就把hibernate相关包和要使用的相关数据库的驱动包全部拷到lib包下。如果java工程就拷到工程下,然后buildPath一下。

第二步配置文件:在Src目录下建一个hibernate.cfg.xml文件。第一行写上xml的版本信息及编码信息。紧接着写hibernate.cfg.xml的头信息。这个头信息当然是记不住啦,会找就行了,从上面的包中的hibernate3(我用的是这个版本的)这个包中找到org.hibernate包。这里有好多相关类,在最下面有两个dtd文件。一个是hibernate-configuration-3.0.dtd和hibernate-mapping-3.0.dtd.打开第一个文件从里面拷出hibernate的头信息,粘贴到hibernate.cfg.xml中的xml信息下面。hibernate.cfg.xml的根结点是<hibernate-configuration>里面有<session-factory>.在<session-factory>里通过<property name="">来指定相关的信息。比如下

<?xml version="1.0" encoding="UTF-8"?>

hibernate配置文件的头信息。从hibernate3的包里找

<hibernate-configuration>

<session-factory>

<property name="connection.driver_class">数据库驱动类</property>中间的下划线不要少

<property name="connnecton.url">数据库URL</property>

<property name="connection.username">数据库用户名</property>

<property name="connection.password">数据库密码</property>

<property name="dialect">数据库方言</property>这里不要加conneciotn上面四个不要少conneciotn

<property name="show_sql">显示sql</property>

<property name="format_sql">格式化sql</property>

.....

.  .....

......

</session-factory>

</hibernate-configuration>

第三步:加载配置文件,连接数据库。当然是有多种方式了。我这里只说自己目前知道的一种。先要引用一个类,这个类很重要当然是在hibernate3这个同名包里了。处理配置文件当然要去配置相关的一个子包时去找了,于是就会发现有一个cfg的子包。没错就是它里面的Configuration这个类。这个类有一个方法configure是接收配置文件的。里面可以不传参数,那么它就会默认去找src下的hibernate.cfg.xml这个文件 。如果改名了就得把名字作为参数传到new Configuration().configure(如里hibernate.cfg.xml改了名字要把文件名的字符串传进来);这个方法除了接收字符串类型的参数外还可以接收File类型,URL类型和Configuration类型的参数。返回类型是Configuration。通过这个Configuration的buildSessionFactory得到一个SessionFactory.再通过这个SessionFactory的openSession()方法得到一个Session.

Configuration configure = new Configuraton().configure();//默认配置文件没有改名和位置

SessionFactory factory = configure.buildSessionFactory();

Session session= factory.openSession();

这样就可以通过session进行数据库的操作了。这里操作通过ORM映射出来对象来操作数据库

第四步:创建POJO类,创建表,创建映射文件:类名.hbm.xml。配置对象关系映射。

既然Hibernate是一个ORM的开源框架,也就是对象关系映射框架。那就得有对象即类,关系即表,映射即类和表的对应配置文件。首先在com.ts.POJO包(持久对象java对象)中新建一个类Collage大学。有cid int,cname String, ccity String, cdate TDate这四个吧。注意这里的Date类型的包是sql包里的。不要选错了。创建一个表id int,name varchar,city varchar,date TDate.好了,现在有对象有关系了,那就建立映射文件一般映射文件表和类名相同。Collage.hbm.xml放到com.ts.pojo下。先写xml的版本和编码信息。这个就不说了。然后声明它的头信息。这个头信息比较长,也不好记,会找就行了。一种方法从hibernate.cfg.xml中把那个头信息拷过来。把里面的configuration改成mapping就行了。注意。大写改大写小写改小写。另一种方法从hibernate的包里找。有一个hibernate-mapping-3.0.dtd文件。跟上面的configuraton的那个文件挨着。拷到这里就行了。下面开始写根结点<hibernate-mapping 这里有个package="这里填写POJO类的包名,那么下面指定class的name时就不用带包名了,否则name就得写全类">里面是<class>
<class>里面的配置。首先配置一个id。id就是数据库持久化标识说明了就是表中的主键,'它有两个属性。name对应的是类里面的持久化标识cid,column对应表中的主键列id,type表示java中的类的cid属性的类型和对应的数据库的表中字段的类型的一个标识。可以采用hibernate的类型。<id name="cid" column="id" type="integer"> id里面有一个子标记generator用于配置主键的生成策略,是由class来指定的。<generator  class="">
主键生成策略:
increment用于为long,short或int类型生成唯一标识。
identity对DB2,Mysql,SQLSERVER,Sybase的内置标识字段提供支持。
sequence在DB2,PostGreSql,oracle等使用序列生成标识。配好后hibernate会创建一个序列。会向数据库发送一条生成队列的语句,生成新的标识。当然也可以不用hibernate创建的。自己手动指定 一个序列。加<param name="sequence">这里写序列名称</param>
hilo高低位算法生成标识
seqhilo高低位算法生成标识
uuid128位的字符串类型的标识符。32位16进制的字符串。
guid SQLSERVER和MySQL中使用数据库生成的GUID字符串
native根据底层数据库的能力选择identity,sequence
assigned由程序生成这个标识
select
foreign
其它的属性对应用<property name="cname" column="name" type="string" length="长度,注意加引号">
<property name="cprovince" column="province" type="string" length="20">还有一个lazy是延迟加载

<property name="cdate" column="c_date" type="date"></property>

全文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.ts.pojo">
    <class name="College" table="t_College">
      <!-- 持久化标识即主键 -->
      <id name="cid" column="cid" type="integer">
      <!-- 主键的生成策略 -->
         <generator class="identity"></generator>
      </id>
      <property name="cname" column="c_name" type="string" length="20"></property>
      <property name="province" column="c_province" type="string" length="20"></property>
      <property name="city" column="c_city" type="string" length="10"></property>
      <property name="cdate" column="c_date" type="date"></property>
    </class>
</hibernate-mapping>

好了,到此我们已经把对象关系映射文件配好了。还要记得在hibernate.cfg.xml的最下面mapping上这个映射文件哦

<mapping resource="com/ts/pojo/Collage.hbm.xml"这里的包用斜杠分开。切记不要用点。

第五步:通过hibernate创建表

可以通过下面代码创建表。需要用到org.hibernate.tool.hbm2ddl.SchemaExport。

Configuration cfg = new Configuration().configure();

SchemaExport se = new ShemaExport(cfg);//需要在ShecmaExport的构造方法中传Configuration的实例cfg

se.create(ture,ture);它的create方法中的两个参数全是True。

CRUD操作创建数据,读取数据,更新数据,删除数据

第六步:通过hibernate做一个增加的操作,即插入纪录

Session session = null;
  Transaction ts = null; //注意要引用hibernate的事务包。不要引用错了。                                              //
  try {
   session = HibernateFactory.getHibernateSession();//Configuration().configure(hibernate.cfg.xml).buildSessionFacorty.openSession();
   College c1 = new College();//创建一个大学的实例,然后给各个属性赋值
   c1.setCname("qinghua");
   c1.setProvince("beijing");
   c1.setCity("haidian");
   c1.setCdate(new Date(System.currentTimeMillis()));//当前时间。sql.Date
   ts = session.beginTransaction();//打开事务,把对数据库的操作纳入事务管理
   session.save(c1);//对象实例传进去保存,各个属性就分自动分配到表的各字段里去

c1.setCname("beijingdaxue");//持久状态的Set方法会发送一条update语句,同时更改数据库中的字段的内容。
ts.commit();//提交事务
   HibernateFactory.closeSession(session);//记得关闭session

c1.setCname("renmindaxue");} catch (HibernateException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

第七步:通过hibernate做一个修改的操作,即更新纪录

顺便学习一下Hibernate中类的对象(比如上面的College)的三种状态。

瞬时状态:当通过构造方法创建一个持久化类的对象时,该对象并没有持久化标识,没有纳入Session管理。没有和表中纪录进行联动。上面C1的斜体状态。

持久化状态:当对象获得持久化标识,并纳入session管理。即和表中的纪录有联动。此时的对象状态为持久化状态。上面代码红色save即是进行了持久化。调用Set方法就会同时发送一条update语句,同时更新数据库中相应的字段内容。后面就是持久化状态了.直到commit..在持久化状态时被delete转化为瞬时状态.

托管状态:也叫游离状态。首先是由对象的持久化状态转变而来的,当该对象具有持久化标识但不和数据库联动,也就是当关闭session.上面蓝色代码时状态。

Session session = null;
  Transaction ts = null; //注意要引用hibernate的事务包。不要引用错了。                                              //
  try {
   session = HibernateFactory.getHibernateSession();//Configuration().configure(hibernate.cfg.xml).buildSessionFacorty.openSession();
   College c1 = new College();//创建一个大学的实例,然后给属性赋值
   c1.setCid(1);
   c1.setCname("北大");//没有给其它字段赋值,所以会标识为1的那条纪录其它的字段置空的,切记,谨慎。
   ts = session.beginTransaction();//打开事务,把对数据库的操作纳入事务管理
   session.update(c1);//
   ts.commit();//提交事务
   HibernateFactory.closeSession(session);//记得关闭session
  } catch (HibernateException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

注意上面是有问题的更新操作,因为c1只是给id和name赋了值。其它属性都是空,而下面又调用了update(c1)这个无条件执行的更新。所以会把数据库中标识为1那条纪录的除了id和name外的字段都强制更新为空值。正确的方法是先向数据库发送查询语句,通过标识查到值后赋给对象的各属性,然后再更新。可以通过c1=session.get(College.class,1);这个session的get()方法有两个参数,一个是要创建对象的类的类,一个是序列化标识id。session的get()方法是即时发送的。它还有一个load()方法,参数和get()方法一样,却是延迟发送sql语句。

Session session = null;
  Transaction ts = null; //注意要引用hibernate的事务包。不要引用错了。                                              //
  try {
   session = HibernateFactory.getHibernateSession();//Configuration().configure(hibernate.cfg.xml).buildSessionFacorty.openSession();
   College c1 = null;//这里不创建,get时创建对象实例
   c1 = (College)session.get(College.class, 2);//将要被修改的对象纳入session管理。get()方法会立即发送sql语句。不是load
   c1.setCname("北大");//当调用set方法时。它会判断你给的新值是否跟从数据库中取的值是否相同。相同时不发送update语句。不同时发送update语句更新数据库。
   ts = session.beginTransaction();//打开事务,把对数据库的操作纳入事务管理
   //session.update(c1);//对象实例传进去保存,各个属性就分自动分配到表的各字段里去
   ts.commit();//提交事务
   HibernateFactory.closeSession(session);//记得关闭session
  } catch (HibernateException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

这里不用下面的session.update()也行。上面通过session.get()方法进行持久化后,再调用set方法就会自动发送update语句,当然是先判断新值和旧值是否相同,不相同时才发送update更新数据库。相同时就不发送了,是不是比较智能啊。

另外session还有一个saveOrUpdate(c1)方法,注意大小写。这个比较适合用于不是自动生成主键的情况,比如主键生成策略为assign即程序指定。这个方法执行时会先发送一条查询语句根据主键标识,如果没有就插入一条。有了判断是否相同,不同则更新,相同则不更新。

第八步:删除纪录

Session session = null;
  Transaction ts = null; //注意要引用hibernate的事务包。不要引用错了。                                              //
  try {
   session = HibernateFactory.getHibernateSession();//Configuration().configure(hibernate.cfg.xml).buildSessionFacorty.openSession();
   College c1 = new College();
   c1.setCid(1);
   ts = session.beginTransaction();//打开事务,把对数据库的操作纳入事务管理
   session.delete(c1);
   ts.commit();//提交事务
   HibernateFactory.closeSession(session);//记得关闭session
  } catch (HibernateException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

先创建一个类。然后给这个类指定标识,下面调用session.delete(c1);就行了。这里的实例参数只要有唯一标识就行,不要求其它属性都得有值。

第九步:立即加载和延迟加载

hibernate的Session有get()和load()方法。它们的参数相同。区别是get()是立即加载,调用后马上发送sql语句到数据库。不管持久对象是否调用了get方法。

Session session = null;
  Transaction ts = null;
  session = HibernateFactory.getHibernateSession();
  College c1 = null;
  c1 = (College)session.get(College.class, 2);//立即加载。立即发送sql语句到数据库,不管有没有用到get方法,无论下行有没有被注释掉都会发送

//System.out.println(c1.getCid()+","+c1.getCname()+","+c1.getProvince());
  HibernateFactory.closeSession(session);

而load()方法在当College.hbm.xml的Class结点的lazy属性为true时,默认就是true的。调用load()方法后不会马上发送sql到数据库不会马上加载。而是当session关闭前如果有调用get()方法时才会发送查询语句,否则不发送。

Session session = null;
  Transaction ts = null;
  session = HibernateFactory.getHibernateSession();
  College c1 = null;
  c1 = (College)session.load(College.class, 2);//延迟加载。延迟发送sql语句到数据库,如果没有用到get方法就不发送。当然也受College.hbm.xml的Class结点的lazy属性控制。默认是True
  //System.out.println(c1.getCid()+","+c1.getCname()+","+c1.getProvince());
  HibernateFactory.closeSession(session);

以下是常见的数据库驱动类,方言。url。连接池相关属性先存在这里。以后备用呵呵------------------------------------

######################
### Query Language ###
######################

## define query language constants / function names

hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N'

## Query translator factory class

hibernate.query.factory_class @QUERY_TRANSLATOR_FACTORY@

#################
### Platforms ###
#################

hibernate.dialect @HIBERNATE_DIALECT@
hibernate.connection.driver_class @DRIVER_CLASS@
hibernate.connection.username @DB_USERNAME@
hibernate.connection.password @DB_PASSWORD@
hibernate.connection.url @DB_URL@

## 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:hsql://localhost
#hibernate.connection.url jdbc:hsqldb:test
#hibernate.connection.url jdbc:hsqldb:.

## MySQL

#hibernate.dialect org.hibernate.dialect.MySQLDialect
#hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect
#hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect
#hibernate.connection.driver_class org.gjt.mm.mysql.Driver
#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.OracleDialect
#hibernate.dialect org.hibernate.dialect.Oracle9Dialect
#hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver
#hibernate.connection.username ora
#hibernate.connection.password ora
#hibernate.connection.url jdbc:oracle:thin:@localhost:1521:test

## 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
#hibernate.query.substitutions yes 'Y', no 'N'

## DB2

#hibernate.dialect org.hibernate.dialect.DB2Dialect
#hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver
#hibernate.connection.url jdbc:db2:test
#hibernate.connection.username db2
#hibernate.connection.password db2

## TimesTen (not supported yet)

#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:/test;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.00/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

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

#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

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

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

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

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

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

## choose a custom SQL exception converter

#hibernate.jdbc.sql_exception_converter

##########################
### Second-level Cache ###
##########################

## optimize chache 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.provider_class org.hibernate.cache.EhCacheProvider
#hibernate.cache.provider_class org.hibernate.cache.EmptyCacheProvider
hibernate.cache.provider_class org.hibernate.cache.HashtableCacheProvider
#hibernate.cache.provider_class org.hibernate.cache.TreeCacheProvider
#hibernate.cache.provider_class org.hibernate.cache.OSCacheProvider
#hibernate.cache.provider_class org.hibernate.cache.SwarmCacheProvider

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

Hibernate初级知识学习(1)相关推荐

  1. 【软件创新实验室2021年暑假集训】Java技术培训——Java前置知识学习

    [软件创新实验室2021年暑假集训]Java技术培训--Java前置知识学习 文章目录 [软件创新实验室2021年暑假集训]Java技术培训--Java前置知识学习 前言 一.了解计算机 1.计算机的 ...

  2. 虚幻引擎的数学知识学习教程 Math for Unreal Engine (Early Preview)

    通过做真实世界的 Unreal Engine项目来学习数学 你会学到什么 理解游戏开发对数学的基本需求 将数学直接应用到用例中,而不是钻研理论(用我们的示例项目进行实践) 正确编辑短视频,节省您的时间 ...

  3. 三代测序知识学习----Sequel

    三代测序知识学习----Sequel (2017-03-26 22:38:34) 转载▼   分类: 三代 知识链接:http://www.pacb.com/blog/new-chemistry-so ...

  4. 计算机二级二叉树基础知识,2017年计算机二级公共基础知识学习教程:树与二叉树...

    (六)树与二叉树 1.树的基本概念 树是一种简单的非线性结构.在树结构中,数据元素之间有着明显的层次结构.在树的图形表示中,用直线连接两端的结点,上端点为前件,下端点为后件. 在树结构中,每一个结点只 ...

  5. c语言运算符ppt,C语言知识学习运算符.ppt

    C语言知识学习运算符.ppt 第三章,C语言运算符,回顾,变量和常量的含义 熟悉基本数据类型 - int.char.float 和 double 使用算术运算符 理解类型转换 熟练使用 scanf 和 ...

  6. 安全测试3_Web后端知识学习

    其实中间还应该学习下web服务和数据库的基础,对于web服务大家可以回家玩下tomcat或者wamp等东西,数据库的话大家掌握基本的增删该查就好了,另外最好掌握下数据库的内置函数,如:concat() ...

  7. Python 基础知识学习笔记——NumPy

    Python基础知识学习笔记--NumPy 与 matlab 优秀的矩阵运算类似,python 提供了 numpy 库,这对熟悉 matlab 的用户来说非常友好.向量.矩阵和多维数组是数值计算中必不 ...

  8. Python 基础知识学习笔记——OpenCV(1)

    Python 基础知识学习笔记--OpenCV(1) OpenCV是一个开源的跨平台计算机视觉和机器学习软件库,它轻量而且高效,被广泛的使用. 整理一下OpenCV学习笔记,以防忘记. 文章目录 Py ...

  9. Python基础知识学习笔记——Matplotlib绘图

    Python基础知识学习笔记--Matplotlib绘图 整理python笔记,以防忘记 文章目录 Python基础知识学习笔记--Matplotlib绘图 一.绘图和可视化 1.导入模块 2.一个简 ...

最新文章

  1. 【Qt】Qt再学习(九):并发 QtConcurrent、QFuture、QFutureWatcher
  2. python电影数据分析的代码_python-small-examples
  3. 中国独角兽企业总榜发布:百亿超级独角兽达13家(附榜单)
  4. 002_Maven命令
  5. CSS基础(part4)--CSS的层叠性继承性优先级
  6. 搬运 centos7.2 apache 绑定二级目录 访问依然是apache页面
  7. java实现递归层次遍历_Java实现二叉树的前序、中序、后序、层序遍历(递归方法)...
  8. “横平竖直”进行连线+将相邻框进行合并
  9. 查看gradle dependencies
  10. 安装VS2012番茄助手
  11. python tkinter 窗口 隐藏 显示_【Python GUI】隐藏窗体和弹窗窗体的探索
  12. js-xlsx使用-解析生成xlsx文件
  13. Android实践:基于聚合数据的手机号码归属地查询
  14. 电脑之间快速传输超大文件(100GB以上)的方法
  15. tensor如何实现转置_pytorch tensor 变换
  16. nmap常用命令/使用教程
  17. 处理el获取session值:严重: Servlet.service() for servlet [LoginServlet] in context with path [/LDMS]...
  18. 《黑客与画家》读书笔记(六)
  19. html5 中心点旋转,html5 canvas围绕中心点旋转
  20. Word2Vec+ Word Embedding

热门文章

  1. 黑夜给了我黑色的眼睛,我却用它研究CV
  2. 六肽-9/CAS号:1228371-11-6——祛皱能手
  3. Unity3D开发体验之Unity3D 脚本开发
  4. ios判断设备能否打电话、发短信
  5. 软件测试面试——如何测试一个杯子
  6. SpringMVC工作流程(详-小白版)
  7. Android安卓开发大作业---模拟电影票小程序APP
  8. 谷歌地图的纵横功能将于8月9日停用
  9. 【休闲游戏思考】超轻休闲游戏——从立项到起量
  10. 【毕业设计】时间序列的股票预测与分析系统 - python 大数据