Hibernate-Configuration

Hibernate 需要提前知道去哪里查找java类与表之间的映射信息,它同样需要知道数据库的配置信息以及其它一些相关的初始化信息。这些信息都填写在Hibernate.properties和Hibernate.cfg.xml里面。

那Hibernate.properties和Hibernate.cfg.xml怎么用呢?按官方推荐的写法都是在classpath下。Hibernate.properties的参数都有默认值。

一般hibernate.properties修改的配置项

hibernate.dialect 
hibernate.connection.driver_class
hibernate.connection.url
hibernate.connection.username
hibernate.connection.password
hibernate.connection.pool_size
hibernate.connection.autocommit

Hibernate.cfg.xml一般长这样 

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
   <session-factory>
   <property name="hibernate.dialect">
      org.hibernate.dialect.MySQLDialect
   </property>
   <property name="hibernate.connection.driver_class">
      com.mysql.jdbc.Driver
   </property>
   <property name="hibernate.connection.url">
      jdbc:mysql://localhost/test
   </property>
   <property name="hibernate.connection.username">
      dbusername
   </property>
   <property name="hibernate.connection.password">
      dbuserpasswd
   </property>

   <!-- List of XML mapping files -->
   <mapping resource="Employee.hbm.xml"/>

</session-factory>
</hibernate-configuration>

有了上面两个文件,hibernate已经有足够的信息启动,并且准备为你的应用服务了。

稍提一下:hibernate.dialect ,hibernate的方言。之前我提到过,数据库作为一个独立的学科,门派也非常多。Mysql有自己的特性,Oracle也有自己的特性,SQL Server 也如此。hibernate它既然敢站在应用前面,说它深谙数据库之道,一切数据库相关的事务都交给它,必定是有与各数据库打交道的能力。hibernate通过学会各数据库方言,从而顺利的“沟通”。

DB2org.hibernate.dialect.DB2Dialect
HSQLDBorg.hibernate.dialect.HSQLDialect
HypersonicSQLorg.hibernate.dialect.HSQLDialect
Informixorg.hibernate.dialect.InformixDialect
Ingresorg.hibernate.dialect.IngresDialect
Interbaseorg.hibernate.dialect.InterbaseDialect
Microsoft SQL Server 2000org.hibernate.dialect.SQLServerDialect
Microsoft SQL Server 2005org.hibernate.dialect.SQLServer2005Dialect
Microsoft SQL Server 2008org.hibernate.dialect.SQLServer2008Dialect
MySQLorg.hibernate.dialect.MySQLDialect
Oracle (any version)org.hibernate.dialect.OracleDialect
Oracle 11gorg.hibernate.dialect.Oracle10gDialect
Oracle 10gorg.hibernate.dialect.Oracle10gDialect
Oracle 9iorg.hibernate.dialect.Oracle9iDialect
PostgreSQLorg.hibernate.dialect.PostgreSQLDialect
Progressorg.hibernate.dialect.ProgressDialect
SAP DBorg.hibernate.dialect.SAPDBDialect
Sybaseorg.hibernate.dialect.SybaseDialect
Sybase Anywhereorg.hibernate.dialect.SybaseAnywhereDialect

真是十八般武艺,样样精通啊!

就是这么神奇!一切犹如买个手机、插张卡、更新一下网络那么简单。

 

 

转载于:https://my.oschina.net/zhouhaojie/blog/818852

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值