随笔-4  评论-0  文章-0  trackbacks-0

1 四种方式配置Configuration:
传递一个java.util.Properties给Configuration.setProperties();
放置hibernate.properties在classpath路径下;
设置System属性,java -D property=value;
在hibernate.cfg.xml放置<property>元素。

Configuration cfg = new Configuration()
  .addClass()
  .addProperty(


2 获取SessionFactory:如果有多个database, 可以获取多个。

SessionFactory sessions = cfg.buildSessionFactory();


3 JDBC connections

Session session = sessions.openSession();

为了获取connection,我们需要传递一些属性给Hiberante,以下的属性定义在org.hibernate.cfg.Environment.
Hibernate通过java.sql.DriverManager获取connection.
这些属性包括:
hibernate.connection.driver_class
hibernate.connection.url
hibernate.connection.username
hibernate.connection.password
hibernate.connection.pool_size
Hibernate Datasource 属性:
hibernate.connection.datasource
hibernate.jndi.url
hibernate.jndi.class
hibernate.connection.username
hibernate.connection.password

4 可选择的hibernate 属性
hibernate.dialect: 常用的有:org.hibernate.dialect.MySQLDialect, OracleDialect,Oracle9Dialect,SQLServerDialect
hibernate.show_sql
...

5 Hibernate 日志
Hibernate使用Apache commons-logging.

6 XML配置文件
...
<hibernate-configuration>
 <session-factory name"">
  <property>
  ...
 </session-factory>
</hibernate-configuration>

SessionFactory sf = new Configuration()
  .configure(
"xxx.xml"//可以缺省xxx.xml
  .buildSessionFactory();

 

posted on 2008-05-21 17:44 火炼子 阅读(2248) 评论(0)  编辑  收藏 所属分类: JAVA应用

只有注册用户登录后才能发表评论。


网站导航: