調用JPA的代碼如下
EntityManagerFactory emf = PersistencecreateEntityManagerFactory(TestSSHPU);
EntityManager em = emfcreateEntityManager();
emgetTransaction()begin();
comhadesleejpaentityPerson p = new comhadesleejpaentityPerson();
psetAge();
psetName(千裡冰封);
comhadesleejpaentityDepartment dept = emfind(comhadesleejpaentityDepartmentclass LongvalueOf());
Systemoutprintln(找到的dept= + dept);
emremove(dept);
emgetTransaction()commit();
調用hibernate的代碼如下
Session session = HibernateUtil
getSessionFactory()
getCurrentSession();
session
getTransaction()
begin();
Department dept = (Department) session
load(Department
class
);
session
delete(dept);
session
getTransaction()
commit();
最後發現是JPA是不能刪除的而hibernate這邊的調用可以刪除一開始我還以為是toplink的實現問題後來特意把實現改成hibernate的實現也同樣所以有可能是JPA的要求必須得這樣做不能替我們自動完成一些東西是利於安全這可能就是標准和流行的差別吧呵呵
[] [] [] [] []
From:http://tw.wingwit.com/Article/program/Java/ky/201311/29048.html