hibernate配置文件hibernate.cfg.xml的详细解释

<!--标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式--><wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr> &lt;?xmlversion='1.0'encoding='gb2312'?&gt;<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<!--表明解析本XML文件的DTD文档位置,DTD是Document Type Definition的缩写,即文档类型的定义,XML解析器使用DTD文档来检查XML文件的合法性。hibernate.sourceforge.net/hibernate-configuration-3.0dtd可以在Hibernate3.1.3软件包中的src\org\hibernate目录中找到此文件--><wbr></wbr>
<!DOCTYPE hibernate-configurationPUBLIC<wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> "-//Hibernate/HibernateConfiguration DTD 3.0//EN"<wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr>"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;<wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr>&lt;!--声明Hibernate配置文件的开始--&gt;<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr>&lt;hibernate-configuration&gt;<wbr></wbr></wbr></wbr>
<wbr><wbr>&lt;!--表明以下的配置是针对session-factory配置的,SessionFactory是Hibernate中的一个类,这个类主要负责保存HIbernate的配置信息,以及对Session的操作--&gt;<wbr></wbr></wbr></wbr>
<wbr><wbr><wbr>&lt;session-factory&gt;<wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr>&lt;!--配置数据库的驱动程序,Hibernate在连接数据库时,需要用到数据库的驱动程序--&gt;<wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> &lt;propertyname="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;<wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr>&lt;!--设置数据库的连接url:jdbc:mysql://localhost/hibernate,其中localhost表示mysql服务器名称,此处为本机,<wbr><wbr>hibernate是数据库名--&gt;<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr>&lt;propertyname="hibernate.connection.url"&gt;jdbc:mysql://localhost/hibernate&lt;/hibernate&gt;<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr>&lt;!--连接数据库是用户名--&gt;<wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> &lt;propertyname="hibernate.connection.username"&gt;root&lt;/property&gt;<wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr>&lt;!--连接数据库是密码--&gt;<wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> &lt;propertyname="hibernate.connection.password"&gt;123456&lt;/property&gt;<wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr>&lt;!--数据库连接池的大小--&gt;<wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> &lt;propertyname="hibernate.connection.pool.size"&gt;20&lt;/property&gt;<wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr>&lt;!--是否在后台显示Hibernate用到的SQL语句,开发时设置为true,便于差错,程序运行时可以在Eclipse的控制台显示Hibernate的执行Sql语句。项目部署后可以设置为false,提高运行效率--&gt;<wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr> &lt;propertyname="hibernate.show_sql"&gt;true&lt;/property&gt;<wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr>&lt;!--jdbc.fetch_size是指Hibernate每次从数据库中取出并放到JDBC的Statement中的记录条数。FetchSize设的越大,读数据库的次数越少,速度越快,FetchSize越小,读数据库的次数越多,速度越慢--&gt;<wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr> &lt;propertyname="jdbc.fetch_size"&gt;50&lt;/property&gt;<wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr>&lt;!--jdbc.batch_size是指Hibernate批量插入,删除和更新时每次操作的记录数。BatchSize越大,批量操作的向数据库发送Sql的次数越少,速度就越快,同样耗用内存就越大--&gt;<wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr> &lt;propertyname="jdbc.batch_size"&gt;23&lt;/property&gt;<wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr>&lt;!--jdbc.use_scrollable_resultset是否允许Hibernate用JDBC的可滚动的结果集。对分页的结果集。对分页时的设置非常有帮助--&gt;<wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr> &lt;propertyname="jdbc.use_scrollable_resultset"&gt;false&lt;/property&gt;<wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr>&lt;!--connection.useUnicode连接数据库时是否使用Unicode编码--&gt;<wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr> &lt;propertyname="Connection.useUnicode"&gt;true&lt;/property&gt;<wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr>&lt;!--connection.characterEncoding连接数据库时数据的传输字符集编码方式,最好设置为gbk,用gb2312有的字符不全--&gt;<wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> &lt;propertyname="connection.characterEncoding"&gt;gbk&lt;/property&gt;<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr> &lt;!--hibernate.dialect只是Hibernate使用的数据库方言,就是要用Hibernate连接那种类型的数据库服务器。--&gt;<wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> &lt;propertyname="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;<wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr>&lt;!--指定映射文件为“hibernate/ch1/UserInfo.hbm.xml”--&gt;<wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> &lt;mappingresource="org/mxg/UserInfo.hbm.xml"/&gt;<wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr>&lt;/session-factory&gt;<wbr></wbr></wbr>
<wbr>&lt;/hibernate-configuration&gt;<wbr><wbr><wbr></wbr></wbr></wbr></wbr>
<wbr><wbr></wbr></wbr>
<wbr><wbr></wbr></wbr>
<wbr><wbr></wbr></wbr>
<wbr> &lt;beanid="dataSource"<wbr><wbr></wbr></wbr></wbr>
<wbr>class="org.apache.commons.dbcp.BasicDataSource"<wbr><wbr></wbr></wbr></wbr>
<wbr>destroy-method="close"&gt;<wbr><wbr></wbr></wbr></wbr>
//连接驱动<wbr><wbr><wbr></wbr></wbr></wbr>
<wbr> &lt;property name="driverClassName"value="${jdbc.driverClassName}"/&gt;<wbr><wbr></wbr></wbr></wbr>
//连接url,<wbr><wbr><wbr></wbr></wbr></wbr>
<property name="url" value="${jdbc.url}"/><wbr><wbr></wbr></wbr>
//连接用户名<wbr><wbr><wbr></wbr></wbr></wbr>
<wbr> &lt;property name="username"value="${jdbc.username}"/&gt;<wbr><wbr></wbr></wbr></wbr>
//连接密码<wbr><wbr><wbr></wbr></wbr></wbr>
<wbr> &lt;property name="password"value="${jdbc.password}"/&gt;<wbr><wbr></wbr></wbr></wbr>
</bean><wbr><wbr></wbr></wbr>
<wbr><wbr></wbr></wbr>
<beanid="hbSessionFactory"<wbr><wbr></wbr></wbr>
<wbr>class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactory<wbr>Bean"&gt;<wbr><wbr></wbr></wbr></wbr></wbr>
<wbr> &lt;property name="dataSource"ref="dataSource"/&gt;<wbr><wbr></wbr></wbr></wbr>
<wbr> &lt;propertyname="configLocation"&gt;<wbr><wbr></wbr></wbr></wbr>
//hibernate配置文件位置<wbr><wbr><wbr></wbr></wbr></wbr>
<wbr>&lt;value&gt;WEB-INF/hibernate.cfg.xml&lt;/value&gt;<wbr><wbr></wbr></wbr></wbr>
<wbr>&lt;/property&gt;<wbr><wbr></wbr></wbr></wbr>
<wbr> &lt;propertyname="configurationClass"<wbr><wbr></wbr></wbr></wbr>
<wbr>value="org.hibernate.cfg.AnnotationConfiguration"/&gt;<wbr><wbr></wbr></wbr></wbr>
<wbr> &lt;propertyname="hibernateProperties"&gt;<wbr><wbr></wbr></wbr></wbr>
<wbr>&lt;props&gt;<wbr><wbr></wbr></wbr></wbr>
<wbr>//针对oracle数据库的方言,特定的关系数据库生成优化的SQL<wbr><wbr><wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> &lt;propkey="hibernate.dialect"&gt;<wbr><wbr></wbr></wbr></wbr></wbr>
<wbr><wbr>org.hibernate.dialect.OracleDialect<wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr>&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr></wbr>
<wbr> //选择HQL解析器的实现<wbr><wbr><wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> &lt;propkey="hibernate.query.factory_class"&gt;<wbr><wbr></wbr></wbr></wbr></wbr>
<wbr><wbr>org.hibernate.hql.ast.ASTQueryTranslatorFactor<wbr>y<wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr>&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr></wbr>
<wbr><wbr>//是否在控制台打印sql语句<wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> &lt;propkey="hibernate.show_sql"&gt;true&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr></wbr>
<wbr><wbr>//在Hibernate系统参数中hibernate.use_outer_join被打开的情况下,该参数用来允许使用outerjoin来载入此集合的数据。<wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> &lt;propkey="hibernate.use_outer_join"&gt;true&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr></wbr>
<wbr>//默认打开,启用cglib反射优化。cglib是用来在Hibernate中动态生成PO字节码的,打开优化可以加快字节码构造的速度<wbr><wbr><wbr></wbr></wbr></wbr></wbr>
<wbr> &lt;propkey="hibernate.cglib.use_reflection_optimizer"&gt;true&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr>
<wbr> //输出格式化后的sql,更方便查看<wbr><wbr><wbr></wbr></wbr></wbr></wbr>
<wbr> &lt;propkey="hibernate.format_sql"&gt;true&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr>
<wbr>//“useUnicode”和“characterEncoding”决定了它是否在客户端和服务器端传输过程中进行Encode,以及如何进行Encode<wbr><wbr><wbr></wbr></wbr></wbr></wbr>
<wbr> &lt;propkey="hibernate.connection.useUnicode"&gt;true&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr>
<wbr> //允许查询缓存, 个别查询仍然需要被设置为可缓存的.<wbr><wbr><wbr></wbr></wbr></wbr></wbr>
<wbr> &lt;propkey="hibernate.cache.use_query_cache"&gt;false&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr>
<wbr> &lt;propkey="hibernate.default_batch_fetch_size"&gt;16&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr>
<wbr><wbr>//连接池的最大活动个数<wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> &lt;propkey="hibernate.dbcp.maxActive"&gt;100&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr></wbr>
<wbr> //当连接池中的连接已经被耗尽的时候,DBCP将怎样处理(0 = 失败,1 =等待,2<wbr> =<wbr> 增长)<wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> &lt;propkey="hibernate.dbcp.whenExhaustedAction"&gt;1&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> //最大等待时间<wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> &lt;propkey="hibernate.dbcp.maxWait"&gt;1200&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr></wbr>
<wbr><wbr>//没有人用连接的时候,最大闲置的连接个数<wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> &lt;propkey="hibernate.dbcp.maxIdle"&gt;10&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> ##以下是对preparedstatement的处理,同上。<wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> &lt;propkey="hibernate.dbcp.ps.maxActive"&gt;100&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> &lt;propkey="hibernate.dbcp.ps.whenExhaustedAction"&gt;1&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> &lt;propkey="hibernate.dbcp.ps.maxWait"&gt;1200&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr></wbr>
<wbr><wbr> &lt;propkey="hibernate.dbcp.ps.maxIdle"&gt;10&lt;/prop&gt;<wbr><wbr></wbr></wbr></wbr></wbr>
<wbr>&lt;/props&gt;<wbr><wbr></wbr></wbr></wbr>
<wbr>&lt;/property&gt;<wbr><wbr></wbr></wbr></wbr>
</bean><wbr></wbr>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值