標籤: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