I am having a bidirectional relationship between objects. And have cascade all defined on the opposite side e.g.
DeskImpl Class =========== @OneToMany(mappedBy="desk", fetch = FetchType.EAGER, cascade = { CascadeType.ALL }, targetEntity = BookImpl.class) public Set<Book> getBooks() { return books; }
BookImpl.class =========== @ManyToOne(fetch = FetchType.EAGER, targetEntity = DeskImpl.class) @JoinColumn(name = "oid_desk") public Desk getDesk() { return desk; } I have a column entityId which along with version has a unique constraint on it. Whenever the Desk it updated there is a newer version of desk created and it is attached to the same Book and persisted. and the older desk is unlinked from the book (This happens within its own tx and I see the data correctly reflected in the database.)
This is a unit test I am running =================== 1) Update the desk (As mentioned earlier I am able to see these changes) 2) delete the desk (I expect the delete on desk to cascase to book). However if I run this entire operation as one unit test (Although I am running each operation (update, delete) in it own tx) I get the error on the delete operation. Caused by: org.hibernate.ObjectDeletedException: deleted entity passed to persist: [com.jpm.ibt.primegps.domain.reference.BookImpl#<null>]
3) If I run the update as a seperate test (as mentioned the database changes are seen fine) and then I do another test by looking up that desk and then doing the remove. The operation is successfull without any issues.
It has led me to believe there is definitely some bug in the hibernate implementation where within a particular session it is not able to perform two operations update and delete consistently.
Please let me know if anyone has seen this issue before and how to resolve it. It seems a bit strange.
|