-->
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.  [ 2 posts ] 
Author Message
 Post subject: Update parent while deleting a child
PostPosted: Fri Jan 29, 2010 8:54 am 
Newbie

Joined: Fri Jan 29, 2010 8:37 am
Posts: 5
Hi to all,
i have three tables: Event - Comment - Place
Both events and places can have comments, so that the Event entity has a bidirectional <one-to-many> association with Comment, and Place has a bidirectional <one-to-many> association with Comment too.
The comment can be associated with an event or a place, but not with both.
The Comment has therefore two, not optional joins (because i don't know whether it will be associated with event or place):

Code:
<join table="EventComment" inverse="true" optional="true">
      <key column="commentId" />
      <many-to-one name="event" column="eventId" not-null="true" class="Event" />
</join>
<join table="PlaceComment" inverse="true" optional="true">
      <key column="commentId" />
      <many-to-one name="place" column="placeId" not-null="true" class="Place" />
</join>

What i actually wand to do is: when i delete the child entity Comment, i want the parent entity (that could be an Event or a Place) to update its comments collection automatically. I wonder if there is such a cascade propery to achieve this.
What i'd like to avoid is to check for the parent entity class, and then explicitly call [event or place].getComments().remove(comment)

Thanks in advance


Top
 Profile  
 
 Post subject: Re: Update parent while deleting a child
PostPosted: Fri Jan 29, 2010 4:35 pm 
Newbie

Joined: Mon Oct 11, 2004 5:06 pm
Posts: 4
Without knowing much about your setup, the only thing I can think that might get you there is to implement the onDelete method for a Hibernate Interceptor. You get access to objects as they are being deleted from there. It might get squirrely but it's the only way I can think to do what you want.

see http://docs.jboss.org/hibernate/core/3. ... vents.html


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

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.