隨筆-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 火煉子 閱讀(2266) 評論(0)  編輯  收藏 所屬分類: JAVA應用

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


          網站導航:
           
          主站蜘蛛池模板: 新乐市| 大冶市| 柯坪县| 成武县| 布尔津县| 鲜城| 湖南省| 长海县| 泸溪县| 中超| 新丰县| 自贡市| 廉江市| 惠水县| 贡嘎县| 勐海县| 赫章县| 尼玛县| 桃园市| 黄平县| 广水市| 宁阳县| 辉南县| 碌曲县| 水富县| 大冶市| 滦南县| 宜宾市| 新巴尔虎右旗| 洛宁县| 江华| 聊城市| 报价| 文成县| 沅陵县| 泾川县| 盖州市| 菏泽市| 原阳县| 株洲市| 武陟县|