-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Cascading deletes and optional relationships
PostPosted: Tue Jul 10, 2012 11:46 pm 
Newbie

Joined: Tue Jul 10, 2012 11:29 pm
Posts: 1
Sorry if this is obvious but we've been scratching our heads over this for several days now.

Consider three entities, Parent, Child and X:

Parent has a @OneToMany relationship to Child, set up to cascade deletes and orphan removal = true.

Child has a @ManyToOne relationship to Parent with optional = false, further the relationship is @NotNull and @JoinColumn has nullable = false.

X has a @ManyToOne relationship to Child with optional = true.

Here's what we'd ideally like to have happen when we delete a Parent. We'd like the delete to cascade and remove all Child rows that correspond to the deleted Parent. No problem so far. But we would also like any X that refers to any deleted Child to have the Child relationship nulled out. We do not want to delete any X, we merely want to null out the relationship. This is consistent with it being an 'optional' relationship.

How do we do this in Hibernate? Ideally we want it to be declarative so our business logic doesn't have to 'remember' to come null out these relationships. In fact, if we are to use cascading at all it really has to be declarative, given that there could be many levels of cascading before we come across an optional relationship to be nulled out.

Any hints? We're stumped ....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.