<?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>
hibernate.properties及hibernate.cfg.xml
猜你喜欢
转载自zac110.iteye.com/blog/1121519
今日推荐
周排行