隨筆-4  評論-0  文章-0  trackbacks-0

          1 四種方式配置Configuration:
          傳遞一個java.util.Properties給Configuration.setProperties();
          放置hibernate.properties在classpath路徑下;
          設(shè)置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 火煉子 閱讀(2266) 評論(0)  編輯  收藏 所屬分類: JAVA應(yīng)用

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 华蓥市| 高邑县| 百色市| 永吉县| 布尔津县| 拉萨市| 宜昌市| 红桥区| 镇平县| 黔南| 长葛市| 民和| 龙游县| 柘城县| 思南县| 屏东县| 五大连池市| 吴忠市| 原平市| 宁陕县| 开远市| 仁怀市| 湘潭县| 泰来县| 四子王旗| 伊宁市| 云龙县| 浮山县| 洞口县| 五台县| 利川市| 广灵县| 绩溪县| 洛川县| 孙吴县| 沁阳市| 彭山县| 特克斯县| 阿拉善左旗| 金乡县| 安塞县|