`
zhaole609
  • 浏览: 339622 次
  • 性别: Icon_minigender_1
  • 来自: 河南
社区版块
存档分类
最新评论

hibernate.properties 和 hibernate.cfg.xml

阅读更多
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>
分享到:
评论

相关推荐

    ssh整合,不带hibernate.cfg.xml的方式

    继续在 LocalSessionFactoryBean 中配置,使用hibernateProperties属性继续来配置其他的属性,注意值是properties属性文件

    6 用Properties补充hibernate.cfg.xml配置

    NULL 博文链接:https://elf8848.iteye.com/blog/340731

    Hibernate小例子

    正如其名,Configuration 类负责管理Hibernate 的配置信息。...这些属性在hibernate配置文件(hibernate.cfg.xml 或hibernate.properties)中加以设 定(参见前面“Hibernate配置”中的示例配置文件内容)。

    最简单的Hibernate工程

    一个最简单的Hibernate工程,可通过hibernate.cfg.xml或者hibernate.properties加载数据源并对对象操作,下载后可直接导入eclipse运行

    最简单Hibernate工程代码

    最简单的Hibernate工程代码,可通过hibernate.cfg.xml或者hibernate.properties加载数据源,此工程下载后可直接导入eclipse运行

    Hibernate使用技巧汇总

    两种配置文件: A.hibernate.cfg.xml 和 B.hibernate.properties A中可含映射文件的配置,而B中hard codes加映射文件。 A。Configuration config=new Configuration().config(); B. ...

    spring2.5 struts2.0 hibernate3.2.5 搭建的企业级开发基础模块

    Hibernate:spring.local.hibernate.cfg.xml Struts:struts.xml、struts.properties 配置很简单,用点心看就会了,多的不说了,好好享受咯 哦 忘记介绍了, 当中还有本人写的几个自定义标签:...

    Hibernate实践例子程序

    1) Hibernate全局配置文件,hibernate.properties或者hibernate.cfg.xml.。一般使用XML文件。 2) 数据O/R mapping 配置文件,也就是数据库中每一条记录的详细说明,包括field, PrimaryKey等。*.hbm.xml,*一般用...

    毕业设计+源码(项目管理系统)完整框架

    绝版作品!一切都只是曾经,神马都是浮云!...运行先改jdbc.properties和hibernate.cfg.xml里面的数据库配置!数据库最好事先存在。 再运行test包的testCreateDB-》testData(插入数据!)即可运行!

    hibernate_annotation_所需jar包

    myeclipse的自带hibernate jar包不支持注解;自己找的hibernate注解所需的jar包:hibernate-core;hibernate-annotation;hbm-cfg-xml;log4j.properties

    SSH代码生成工具 SSH代码生成器

    Hibernate3.2配置--&gt; hibernate.cfg.xml JSP文件--&gt; 具有Struts2.0支持的增、删、改、查页面及自定义查询、自动分页等操作 Action--&gt; 业务Action.java和导出Excel的Action等 VO --&gt; bean.java及 bean.hbm.xml配置...

    hibernate-源代码-01

    另一种是XML 格式的配置文件, XML 配置文件的默认名称为 hibernate.cfg,xml。 上述两种格式的配置文件是等价的,具体使用哪个可以自由选择。 XML 格式的配置文件更易于修改,配置能力更强,当改变底层应用配置时不...

    Java框架SSH整合的所有配置文件

    内含有applicationContext.xml,c3p0-config.xml,c3p0-db.properties,hibernate.cfg.xml,log4j.properties,struts.xml,User.hbm.xml,pom.xml等等配置文件

Global site tag (gtag.js) - Google Analytics