在我的Java
應用程序中,我試圖在一個有子對象的父對象上運行cascade delete
。Hibernate中的級聯刪除:從表中刪除什麼命令?
當,當我運行的應用程序,我得到以下錯誤:
java.sql.SQLIntegrityConstraintViolationException: ORA-02292: integrity constraint violated - child record found
...我已經尋找這個錯誤,here它指出,這是由於:
You tried to DELETE a record from a parent table (as referenced by a foreign key), but a record in the child table exists.
我需要刪除全部子表第一個?我認爲級聯刪除的想法是它自動?
代碼:
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("myclasses");
EntityManager em = entityManagerFactory.createEntityManager();
Session session = em.unwrap(Session.class);
Transaction transaction = session.beginTransaction();
try {
String hqlDelete = "DELETE FROM product WHERE price='PRICED'";
Query queryDelete = session.createQuery(hqlDelete);
queryDelete.executeUpdate();
transaction.commit();
} catch (Throwable t) {
transaction.rollback();
throw t;
}
你能粘貼兩個實體類? –
是什麼讓你覺得你正在運行'級聯刪除'? –
,因爲在我的實體中有各種級聯= CascadeType.ALL註釋?對不起,我對hibernate非常陌生 – java123999