-->
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.  [ 5 posts ] 
Author Message
 Post subject: Only update children, but not parent.
PostPosted: Thu Mar 27, 2008 10:46 am 
Newbie

Joined: Fri Jun 16, 2006 9:59 am
Posts: 11
Hello,

I've got a class with a collection in it and it's mapped in hibernate with a one-to-many relationship. Everything there is pretty standard.

Code:
   <class name="CState" entity-name="CState" table="c_state">
      <cache usage="read-write" />
      <id name="id" type="long" column="c_device_id">
         <generator class="foreign">
            <param name="property">state</param>
         </generator>
      </id>

      <set name="alarms" cascade="none" inverse="true" order-by="character_position asc">
         <cache usage="read-write" />
         <key column="c_device_id" not-null="true" />
         <one-to-many entity-name="Alarm" />
      </set>
   <property name="lastModified" type="timestamp" column="last_mod_date_ts" />
   <property name="created" type="timestamp" column="create_date_ts" />
   </class>

<!-- Alarm -->
   <class name="Alarm" entity-name="Alarm" table="alarm_state">
      <cache usage="read-write" />
      <id name="id" type="long" column="alarm_state_id">
         <generator class="sequence">
            <param name="sequence">alarm_state_seq</param>
         </generator>
      </id>

      <property name="cId" type="long" column="c_device_id" not-null="true" />

      <property name="displayChar" type="string" column="alarm_display_character" />
<property name="lastModified" type="timestamp" column="last_mod_date_ts" />
      <property name="created" type="timestamp" column="create_date_ts" />

   </class>


If there is a change in the alarm collection, and I do an update on the parent, the parent object is updated as well as the child object. Nothing has changed in the parent object except the last mod date, which adds a record in a history table via DB trigger.

I'm looking for a way to not update the parent when only a child is changed.

This may seem a bit strange, seeing as how I've found nothing on the web about it, however I'd still like to be able to do this. We're sort of locked in to a situation like this, so fundamental changes are currently impossible with our time constraints.

Thanks


Top
 Profile  
 
 Post subject: Re: Only update children, but not parent.
PostPosted: Thu Mar 27, 2008 11:23 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
You might be looking for dynamic updates. Enable dynamic-update on the parent class and it will only update the last mod date field. Note, parent should have been loaded with the same session that is updating it.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 27, 2008 12:24 pm 
Newbie

Joined: Fri Jun 16, 2006 9:59 am
Posts: 11
Quote:
You might be looking for dynamic updates. Enable dynamic-update on the parent class and it will only update the last mod date field. Note, parent should have been loaded with the same session that is updating it.


Thanks for replying so quickly and sorry for being unclear. The situation is that the children are updated, so hibernate marks the parent as "dirty" as well and so the parent gets written to the database again, even though its own data has not changed, which causes a duplicate record in the table.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 27, 2008 12:25 pm 
Newbie

Joined: Fri Jun 16, 2006 9:59 am
Posts: 11
proxy problem. reply pasted numerous times. sorry.


Last edited by roadblocked on Thu Mar 27, 2008 12:39 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 27, 2008 12:26 pm 
Newbie

Joined: Fri Jun 16, 2006 9:59 am
Posts: 11
proxy problem. reply pasted numerous times. sorry.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.