hibernate.properties及hibernate.cfg.xml

系统 2488 0

hibernate.properties 和 hibernate.cfg.xml是hibernate的配置文件,对于初学者,可能存在一些配置疑难。本文给出了hibernate.properties及hibernate.cfg.xml内容配置样例,二者选其一即可

 

hibernate.properties

##---------- this is the connection and hibernate.dialect fo mysql --------------------------------
hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=org.gjt.mm.mysql.Driver
hibernate.connection.url=jdbc:mysql://ip:3306/databasename?lastUpdateCount=true;useUnicode=true;characterEncoding=gb2312
hibernate.connection.username=root
hibernate.connection.password=    

##---------- this is the connection and hibernate.dialect fo mssqlserver --------------------------------
#hibernate.dialect=net.sf.hibernate.dialect.SQLServerDialect
#hibernate.connection.driver_class=net.sourceforge.jtds.jdbc.Driver
#hibernate.connection.url=jdbc:jtds:sqlserver://IP:1433;DatabaseName=databasename;charset=cp936
#hibernate.connection.username=sa
#hibernate.connection.password=sa

##---------- this is the connection and hibernate.dialect fo ibmdb2 --------------------------------
#hibernate.dialect=net.sf.hibernate.dialect.DB2Dialect
#hibernate.connection.driver_class=COM.ibm.db2.jdbc.app.DB2Driver
#hibernate.connection.url=jdbc:db2:databasename
#hibernate.connection.username=sa
#hibernate.connection.password=sa

##---------- this is the connection and hibernate.dialect fo Oracle --------------------------------
#hibernate.dialect=net.sf.hibernate.dialect.Oracle9Dialect
#hibernate.dialect=net.sf.hibernate.dialect.OracleDialect
#hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
#hibernate.connection.url=jdbc:oracle:thin:@localhost:1521:databasename
#hibernate.connection.username=ora
#hibernate.connection.password=ora

##---------- after is hibernate config

hibernate.show_sql=true
       
hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N'
hibernate.jdbc.use_streams_for_binary=true
hibernate.cache.region_prefix=hibernate.test
hibernate.cache.use_query_cache=true
hibernate.cache.provider_class=net.sf.ehcache.hibernate.Provider
  
hibernate.connection.pool.size=20
hibernate.jdbc.batch_size=25
hibernate.statement_cache.size = 6
jdbc.fetch_size=50 
jdbc.use_scrollable_resultset=false
jdbc.use_scrollable_resultset=false
hibernate.jdbc.use_streams_for_binary=true
hibernate.max_fetch_depth=1

##############################
### Proxool Connection Pool###
##############################

## Properties for external configuration of Proxool

hibernate.proxool.pool_alias netAuditing

## Only need one of the following

#hibernate.proxool.existing_pool true
#hibernate.proxool.xml cfg/proxool.xml
#hibernate.proxool.properties proxool.properties

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


## enable the query cache

hibernate.cache.use_query_cache true


## choose a cache implementation

hibernate.cache.provider_class net.sf.ehcache.hibernate.Provider

 

hibernate.cfg.xml

<! DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"
>

< hibernate-configuration >
< session-factory >
< property  name ="dialect" > net.sf.hibernate.dialect.MySQLDialect </ property >
< property  name ="connection.driver_class" > org.gjt.mm.mysql.Driver </ property >
< property  name ="connection.url" > jdbc:mysql://IP:3306/databasename?lastUpdateCount=true;useUnicode=true;characterEncoding=gb2312 </ property >
< property  name ="connection.driver_class" > org.gjt.mm.mysql.Driver </ property >
< property  name ="connection.username" > root </ property >
< property  name ="connection.password" > root </ property >
< property  name ="show_sql" > false </ property >


<!--  Mapping files  -->
< mapping  resource ="com/orm.hbm.xml" />

</ session-factory >

</ hibernate-configuration >

 

 

 

 

 



hibernate.properties及hibernate.cfg.xml


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论