隨筆-46  評論-64  文章-2  trackbacks-0
          Hibernate 提供了一個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 閱讀(306) 評論(1)  編輯  收藏 所屬分類: Hibernate

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

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 巫山县| 深州市| 白沙| 盈江县| 班玛县| 汝阳县| 玉田县| 兴文县| 浮梁县| 郸城县| 平定县| 台安县| 上虞市| 双鸭山市| 成武县| 西盟| 隆林| 特克斯县| 扎兰屯市| 普洱| 措美县| 红安县| 济阳县| 吉林市| 平昌县| 桃源县| 锡林郭勒盟| 永顺县| 长治市| 修文县| 乌兰察布市| 平凉市| 盘锦市| 江门市| 中西区| 淮北市| 十堰市| 红河县| 正定县| 武清区| 法库县|