[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4301) @CollectionOfElements does not cascade on delete

Lance Hankins (JIRA) noreply at atlassian.com
Sat Jan 8 12:36:05 EST 2011


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

Lance Hankins commented on HHH-4301:
------------------------------------

Same issue here.  We have tons of @ElementCollection uses in our codebase.

We had to resort to an after-the-fact SQL file which has to drop and recreate each of the constraints generated for these @ElementCollection's (simply to append an "on delete cascade" to the constraint).  Yuck.

> @CollectionOfElements does not cascade on delete
> ------------------------------------------------
>
>                 Key: HHH-4301
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4301
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: annotations
>         Environment: Hibernate 3.2.6 GA
> Database: H2 1.0.72
>            Reporter: Nicole Rauch
>
> Consider the following constellation:
> @Embeddable
> public class Foo {
>    // ...
> }
> @Entity
> public class Bar {
>    @CollectionOfElements
>     private Set<Foo> myFoos;
>     // ...
> }
> When I persist a Bar object that contains some Foos, and when I later decide to delete the Bar object, I get a foreign key constraint violation error message because the Foo objects, which contain a reference to the Bar object that owns them, are not deleted automatically. I would expect the default behaviour to be "on delete cascade" because the Foo objects are embeddables, thus they cannot exist on their own without the Bar object that owns them. But there is no way to tell Hibernate to cascade:
> - the @OnDelete annotation is only allowed for OneToMany relations
> - the @Cascade annotation is being ignored
> - there is no "cascade" property for the CollectionOfElements
> So my question is: Why does the cascading not occur automatically, and how do I tell Hibernate to cascade anyways?
> Thanks a lot in advance,
> Nicole

-- 
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