Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > hibernate 配置文件之hibernate.cfg.xml说明
【标  题】:hibernate 配置文件之hibernate.cfg.xml说明
【关键字】:hibernate,hibernate.cfg.xml
【来  源】:http://www.cublog.cn/u/22374/showart.php?id=279729

hibernate 配置文件之hibernate.cfg.xml说明

Your Ad Here
以下是一个简单的配置文件清单:

<?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">
<hibernate-configuration>
 <session-factory>
  <!-- 以下是Oracle配置 -->
  <!-- Oracle驱动程序位置:D:\oracle\ora92\jdbc\lib(前提是你安装了Oracle) -->
  <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
  <property name="connection.url">jdbc:oracle:thin:@localhost:1521:rosy</property>
  <property name="connection.username">HIBERLAB</property>
  <property name="connection.password">TEST</property>
  <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
  
  <!-- MySQL配置,其驱动程序可以到官方网站下载 -->
<!--
   <property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
  <property name="connection.url">jdbc:mysql://localhost:3306/user</property>
  <property name="connection.username">root</property>
  <property name="connection.password">111111</property>
  <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
-->
  
  
  <!-- sql server 第三方驱动插件下载地址 -->
  <!--
http://sourceforge.net/project/showfiles.php?group_id=33291&package_id=25350&release_id=369359 -->
<!--
  <property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
  <property name="connection.url">jdbc:jtds:sqlserver://localhost:1433/j2eeone</property>
  <property name="connection.username">sa</property>
  <property name="connection.password">TEST</property>
 -->  
  <!-- JDBC connection pool (use the built-in) -->
  <property name="connection.pool_size">1</property>
  <!-- Enable Hibernate's automatic session context management -->
  <property name="current_session_context_class">thread</property>
  <!-- Disable the second-level cache  -->
  <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
  <!-- Echo all executed SQL to stdout -->
  <property name="show_sql">true</property>
  <!-- Drop and re-create the database schema on startup -->
  <property name="hbm2ddl.auto">create</property>
  <mapping resource="setting/Event.hbm.xml" />
  <mapping resource="setting/Person.hbm.xml" />
 </session-factory>
</hibernate-configuration>

 
connection.driver_class :连接数据库所要用到的驱动程序。
 
 
connection.url:数据库连接地址。
 
                     
 
connection.username :数据库用户名
 
 
 
connection.password :数据库密码
 
 
connection.pool_size :链接池大小
 
 
 
说明:关于数据库的配置说明可以参考我的下面这篇博客

http://blog.chinaunix.net/u/22374/showart.php?id=151754

dialect :sql的本地方言,根据链接的数据库确定
 
 
current_session_context_class :确定以何种方式产生Session,如thread或jta
 
 
cache.provider_class :hibernate对缓存的支持
 
 
show_sql :是否在后台打印sql,默认为不打印,如果需要打印则设置为true,如果是在程序的调试阶段,可以将其设置为true,但是如果程序已经到了产品化阶段,为了提高程序的效率建议还是设置为false。
 
 
hbm2ddl.auto :每次运行时是否需要重新建立数据库,默认不需要,如果需要每次重新生成数据库,则可以设置为true,如果你是第一次运行程序,通过设置该参数可以自动在本地生成一个工程数据库,但是如果你的数据库中已经存在而且有部分重要数据的情况下,建议不要把这个参数设置为true,否则,hibernate首先会将本地的数据和表结构全部清除,然后再重新建立最新库。(这个一定要切记的!^^)
 
 
mapping resource :对象配置所在地址
hibernate的表结构以及表之间的关系都是通过mapping resource所指向的配置文件生成的。
hibernate的表结构以及表之间的关系的 *.hbm.xml:【上一篇】
perl学习笔记11:【下一篇】
【相关文章】
  • hibernate的表结构以及表之间的关系的 *.hbm.xml
  • 一个Hibernate 的面试题, 现场分析问题
  • PowerDesigner中设置Hibernate一对多,多对一属性
  • JSF+Hibernate+Spring学习
  • 总结hibernate三中关联关系
  • hibernate+spring的一个简单分页实现
  • 一个关于spring+hibernate的例子
  • Hibernate文档--目录
  • Hibernate参考文档-前言
  • Hibernate参考文档-第一章.Hibernate入门
  • 【随机文章】
  • Oracle用户查找死锁进程
  • "大九宫图"
  • JSP中文乱码显示及javascript与JSP变量传递问题
  • c programming language learn notes 8
  • 让Flash动画“闪”在PowerPoint中
  • 关于《二重身宫》
  • 批处理文件中是否可以用变量
  • 深入了解DB2 Universal Database进程(2)
  • Linux下安装Oracle9i
  • linux下使用vim编辑器
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.