`

hibernate.properties及hibernate.cfg.xml

 
阅读更多
 <?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
           "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
           " http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd
">
<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>
<session-factory>

<!-- 加载数据库连接的路径信息 -->
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>

<!-- 加载数据库连接的驱动类 -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>

<!-- 设置访问数据库的SQL语言类型 此处设置的是MYSQL 的SQL 格式 -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- 设置连接数据库的用户名 -->
<property name="connection.username">root</property>

<!-- 设置连接数据库的密码 -->
<property name="connection.password">123456</property>

<property name="hibernate.show_sql">true</property><!--显示的sql语句格式化-->
<property name="format_sql">true</property><!--使显示的sql语句-->

<!-- 数据表映射文件的路径 -->
<mapping resource="com/lsp/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
==============================
<!--标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式-->
                 <?xml version='1.0' encoding='gb2312'?>
<!--表明解析本XML文件的DTD文档位置,DTD是Document Type Definition 的缩写,即文档类型的定义,XML解析器使用DTD文档来检查XML文件的合法性。 hibernate.sourceforge.net/hibernate-configuration-3.0dtd可以在 Hibernate3.1.3软件包中的src/org/hibernate目录中找到此文件-->
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <!--声明Hibernate配置文件的开始-->      
   <hibernate-configuration>
    <!--表明以下的配置是针对session-factory配置的,SessionFactory是Hibernate中的一个类,这个类主要负责保存HIbernate的配置信息,以及对Session的操作-->
      <session-factory>    
     <!--配置数据库的驱动程序,Hibernate在连接数据库时,需要用到数据库的驱动程序-->
          <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
       <!--设置数据库的连接url:jdbc:mysql://localhost/hibernate ,其中localhost表示mysql服务器名称,此处为本机,     hibernate是数据库名-->  
            <property name="hibernate.connection.url">jdbc:mysql://localhost/hibernate</hibernate>
    <!--连接数据库是用户名-->
        <property name="hibernate.connection.username">root</property>
          <!--连接数据库是密码-->
           <property name="hibernate.connection.password">123456</property>          
          <!--数据库连接池的大小-->
         <property name="hibernate.connection.pool.size">20</property>         
         <!--是否在后台显示Hibernate用到的SQL语句,开发时设置为true,便于差错,程序运行时可以在Eclipse的控制台显示Hibernate的执行Sql语句。项目部署后可以设置为false,提高运行效率-->
         <property name="hibernate.show_sql">true</property>
         <!--jdbc.fetch_size是指Hibernate每次从数据库中取出并放到JDBC的Statement中的记录条数。Fetch Size设的越大,读数据库的次数越少,速度越快,Fetch Size越小,读数据库的次数越多,速度越慢-->
         <property name="jdbc.fetch_size">50</property>
         <!--jdbc.batch_size是指Hibernate批量插入,删除和更新时每次操作的记录数。Batch Size越大,批量操作的向数据库发送Sql的次数越少,速度就越快,同样耗用内存就越大-->
         <property name="jdbc.batch_size">23</property>
         <!--jdbc.use_scrollable_resultset是否允许Hibernate用JDBC的可滚动的结果集。对分页的结果集。对分页时的设置非常有帮助-->
        <property name="jdbc.use_scrollable_resultset">false</property>
         <!--connection.useUnicode连接数据库时是否使用Unicode编码-->
         <property name="Connection.useUnicode">true</property>
         <!--connection.characterEncoding连接数据库时数据的传输字符集编码方式,最好设置为gbk,用gb2312有的字符不全-->
   <property name="connection.characterEncoding">gbk</property>       
         
         <!--hibernate.dialect 只是Hibernate使用的数据库方言,就是要用Hibernate连接那种类型的数据库服务器。-->
         <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
         <!--指定映射文件为“hibernate/ch1/UserInfo.hbm.xml”-->         
           <mapping resource="org/mxg/UserInfo.hbm.xml">
</session-factory>
</hibernate-configuration>           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,*一般用...

    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配置...

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

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

    AutoCode代码生成器(SSH版)

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

    ssh代码生成器轻松、快捷

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

    AutoCode代码生成器【SSH版】

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

Global site tag (gtag.js) - Google Analytics