隨筆-46  評論-64  文章-2  trackbacks-0
          Hibernate 提供了一個(gè)hibernate.properties的模板,稍加修改就能得到自己想要的配置效果

          下面這一段XML配置文件中關(guān)于數(shù)據(jù)庫連接方式的配置,可以在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 閱讀(301) 評論(1)  編輯  收藏 所屬分類: Hibernate

          評論:
          # re: Hibernate基礎(chǔ) - 配置 2011-09-02 09:01 | tb
          剛好能用上   回復(fù)  更多評論
            

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 涞源县| 都江堰市| 丰顺县| 策勒县| 凌云县| SHOW| 徐水县| 进贤县| 铅山县| 仙居县| 嘉祥县| 南平市| 平山县| 元朗区| 柳江县| 泰宁县| 察哈| 吉水县| 西畴县| 南安市| 保康县| 佛学| 双辽市| 合山市| 宽城| 肥乡县| 光泽县| 淮南市| 德安县| 萍乡市| 靖西县| 都兰县| 夹江县| 巴马| 千阳县| 浠水县| 玉山县| 庆安县| 固安县| 清镇市| 武夷山市|