Web Project配置Hirbernate

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   ar   sp   檔案   資料   

1:首先找到hibernate-release-4.1.9.Final.zip\hibernate-release-4.1.9.Final\lib\required ,把required裡的所有jar包copy到Web-Inf下的lib包裡,再把訪問資料庫的ODBC.jar包也放進lib裡。

2:添加Hibernate.cfg.xml檔案(放src下)。在hibernate-release-4.1.9.Final.zip\hibernate-release-4.1.9.Final\project\etc下copy現成的hibernate.cfg.xml檔案。

然後把檔案裡帶紅線的都刪了:

<session-factory name="foo">
  <property name="show_sql">true</property>
  <mapping resource="org/hibernate/test/legacy/Simple.hbm.xml"/>
  <class-cache
   class="org.hibernate.test.legacy.Simple"
   region="Simple"
   usage="read-write"/>
 </session-factory>

3:建立好包名和實體類之後,配置對應檔一般以"實體類名.hbm.xml"為檔案名稱。然後再找到Web App Libraries下的hibernate-core-4.1.9.Final.jar點開後再點開第一個包org.hibernate再找到倒數第二個檔案(hibernate-mapping-3.0.dtd),雙擊之後copy裡面的<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">到對應檔的<?xml version="1.0" encoding="UTF-8"?>下。然後再簡單配置一下如:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
      <class name="cn.jnti.bean.county" table="T_county">  --實體類名 對應  表名
        <id name="id">                                                        --主鍵列
          <generator class="sequence"></generator>             --Oracle自動產生序列
        </id>
        <property name="cname"></property>                      --屬性     對應  列名
      </class>
    </hibernate-mapping>

4:再來配置Hibernate.cfg.xml檔案,

完畢.

Web Project配置Hirbernate

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.