天天看點

HelloWorld(XML/annotation)

在hibernate.cfg.xml中兩種版本的HelloWorld的配置

<mapping resource="com/m4java/hibernate/model/Student.hbm.xml" />
<mapping class="com.m4java.hibernate.model.Teacher"/>
           

1.XML版

在pojo類包下寫一個相應的.hbm.xml檔案,例如:

測試方法:

cfg.configure()方法要求hibernate.cfg.xml存放在src目錄下,也可以自己指定,具體的可檢視相關API。

2.annotation

這個版本相對簡單些,主要在pojo類中使用注解,注意引用的包為javax.persistence.XXXXX

測試方法跟XML的一樣。

關于在oracle中實作主鍵自增長:

首先在oracle中建立一個sequence-->create sequence test minvalue 1 maxvalue 100 start with 1 increment by 1;

在配置檔案中如下配置即可: