]
Gail Badner resolved HHH-6917.
------------------------------
Resolution: Duplicate
Assignee: Gail Badner
Persist deleted entity in collection which is not removed from
collection
-------------------------------------------------------------------------
Key: HHH-6917
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-6917
Project: Hibernate Core
Issue Type: Bug
Components: entity-manager
Affects Versions: 4.0.0.Final, 3.6.9
Environment: PostgreSQL 9.0.4, MySQL 5.5, Spring 3.1, JPA 2.0
Reporter: Wong D
Assignee: Gail Badner
Labels: cascade, collection, delete
Attachments: delete-test-src.zip
In one-to-many relationship, hibernate will not delete the entity from the collection if
the entity is deleted from the outside and was not removed from the collection. For
example, we have two classes:
class A { @OneToMany(cascade=CascadeType.ALL) Collection<B> bs; }
class B { @ManyToOne A a;}
A has a collection of B, say b1, b2, b3.
The following code will raise EntityNotFoundException: deleted entity passed to persist
B#null
for(B b : A.bs) {
BService.delete(b); // No call to persist(A)
}
After we delete the b1, the deletion of b2 will cause the error. A complete test case
attached.
I found out before each query org.hibernate.event.def.AbstractFlushingEventListener class
calls prepareEntityFlushes(EventSource session). If I delete one entity B but did not
remove it from the collection A.bs, Hibernate will throw the exception "deleted
entity passed to persist" when persisting A, even I did not call persist A. So the
exception could be thrown any time (for example, it throws when I execute a SELECT
query).
I am expecting a transparent action that Hibernate will update the collection directly.
BTW, I test eclipselink and it did not complain about deleted entity.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: