-->
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: clearing an association upon a delete
PostPosted: Tue Aug 24, 2004 6:56 pm 
Beginner
Beginner

Joined: Thu Sep 11, 2003 12:53 pm
Posts: 23
Hi,

I have 5 or 6 tables all with created by/updated by associations to my table of users. When I delete a user, I'd like to replace all these associations with "null". In other words, if the Product(mapping below) has a many-to-one relationship with User, when the User record is deleted I'd like the Product.created_user and Product.updated_user fields to become null.

What's the easiest way to do this? Is there something clever I can do with an inverse cascaded mapping to make this happen automagically?

I've read the parent/child docs (numerous times), and find the all-delete-orphan cascade works great for most situations (in the inverse relationship), but here I just want to clear the association, not delete the child records.

Thanks, WILL

Code:
<class name="Product" table="product" >
<meta attribute="generated-class">base.Product</meta>
<id name="product_id" column="product_id" type="long">
   <generator class="increment"/>
</id>

<property name="name"      type="string"/>
<property name="type"      type="string"/>

<property name="last_updated"    type="timestamp">
  <column name="update_date" sql-type="DATETIME"/>
</property>
<property name="created"   type="timestamp">
  <column name="creation_date" sql-type="DATETIME"/>
</property>
<many-to-one name="created_user" column="creation_by" class="User" outer-join="true"/>
<many-to-one name="updated_user" column="update_by" class="User" outer-join="true"/>
</class>


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.