[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5028) Calling em.remove() on child object @OneToMany relationship when CascadeType.ALL and FetchType.EAGER are set throws exception

Jesper Steen Møller (JIRA) noreply at atlassian.com
Tue Jan 11 04:46:06 EST 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5028?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39563#action_39563 ] 

Jesper Steen Møller commented on HHH-5028:
------------------------------------------

OP: What were you expecting to happen?

Since you are not removing the child from the @OneToMany collection, and since the collection is loaded into memory, Hibernate is right to attempt to persist the child in the (implicit) flush() operation on the parent, effectively resuscitating the child from the remove operation. The exception is due to HHH-5124. 

If the desired operation was to force the removal from the collection, you need to call remove() on the collection. For a simple OneToMany with a mappedBy on the child, this seems like an undesired overhead (and will work fine if the collection is not loaded), but if the was using a join table, it would be required anyway.

> Calling em.remove() on child object @OneToMany relationship when CascadeType.ALL and FetchType.EAGER are set throws exception
> -----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-5028
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5028
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: entity-manager
>    Affects Versions: 3.5.0-CR-2, 3.5.1
>         Environment: Confirmed bug using MySQL, PostgreSQL, and Hsqldb, which is what the test is configured with. Hibernate version is 3.5.0-CR-2 (see test app pom.xml)
>            Reporter: Jesse Hutton
>         Attachments: HibernateManyToOneEagerRemove.tar.gz
>
>
> Calling em.remove(foo) on the child object of a @OneToMany relationship that is defined with CascadeType.ALL and FetchType.EAGER throws an Exception. The cause is given as:
> javax.persistence.EntityNotFoundException: deleted entity passed to persist:
> And all I'm doing in the test is removing an object. See attached test case.
> If, however, I remove FetchType.EAGER from the @OneToMany relationship, no exception is thrown.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the hibernate-issues mailing list