随笔-46  评论-64  文章-2  trackbacks-0
Hibernate 提供了一个hibernate.properties的模板,稍加修改就能得到自己想要的配置效果

下面这一段XML配置文件中关于数据库连接方式的配置,可以在hibernate.properties中完成
<?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 name="sf">
    
<!-- 
        <property name="hibernate.connection.driver_class">
            org.hsqldb.jdbcDriver
        </property>
        <property name="hibernate.connection.url">
            jdbc:hsqldb:hsql://localhost/HibernateMapping
        </property>
        <property name="hibernate.connection.username">sa</property>
        <property name="hibernate.dialect">
            org.hibernate.dialect.HSQLDialect
        </property>
     
-->
        
<mapping package="cn.heapstack.models" />
        
<mapping class="cn.heapstack.models.User" />
        
<mapping class="cn.heapstack.models.UserInfo" />
    
</session-factory>

    
</hibernate-configuration>
## HypersonicSQL
#$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
hibernate.dialect org.hibernate.dialect.HSQLDialect
hibernate.connection.driver_class org.hsqldb.jdbcDriver
hibernate.connection.username sa
hibernate.connection.password
hibernate.connection.url jdbc:hsqldb:hsql://localhost/HibernateMapping
#$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$



代码示例:
Configuration cfg = new AnnotationConfiguration().configure("./hibernate.cfg.xml");
SessionFactory sf 
= cfg.buildSessionFactory();
Session session 
= sf.openSession();
org.hibernate.Transaction tx
= session.beginTransaction();
tx.commit();
session.close();
posted on 2007-10-26 14:40 jht 阅读(287) 评论(1)  编辑  收藏 所属分类: Hibernate

评论:
# re: Hibernate基础 - 配置 2011-09-02 09:01 | tb
刚好能用上   回复  更多评论
  

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


网站导航: