-->
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.  [ 3 posts ] 
Author Message
 Post subject: Timestamp versioning and generated columns via triggers.
PostPosted: Mon May 01, 2006 10:55 am 
Newbie

Joined: Fri Apr 28, 2006 1:48 pm
Posts: 7
Hello,

I have some columns generated via db triggers, update_ts ( timestamp ) and create_ts ( timestamp ) and it looks that the db trigger won't populate the update_ts column at INSERT, so update_ts is NULL untill an update command is issued. "Update_ts" column is used for versioning in my hibernate mapping and it looks that even I have defined the timestamp column as below Hibernate won't treat an entity as deattached and will try to persist it instead ( issue an INSERT when I would expect an UPDATE).


<id name="pers_id" type ="long"
column="PERS_ID"
unsaved-value="0">
<generator class="sequence">
<param name="sequence">pers_id_seq</param>
</generator>
</id>

<timestamp
column="UPDATE_TS"
name="UpdateTs"
access="property"
source="db"
generated="always"
unsaved-value="undefined"/>

Having undaved-values as undefined I would expect Hibernate to issue an UPDATE if the pers_id is not 0; it looks that if the update_ts is NULL and pers_id is greater than 0 Hibernate will consider the object as transient not deattached as I would want. Everything works just fine if I change the update_ts column definition in the hibernate mapping to

<timestamp
column="UPDATE_TS"
name="UpdateTs"
access="property"
source="vm"
generated="never"
unsaved-value="undefined"/>




Is there any workaround for this scenario? I would preffer not to change the db trigger.

Any suggestions? thoughts?

Thanks,
Valy


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 4:23 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
Within DB schema having update_ts column with default value of sysdate (as in oracle) is working fine with me. Whenever I insert a new record, both create_ts and update_ts will have same information. And when the application updates the record, I will just pass on new date information to the update_ts column.

the following lines in the mapping are enough on my side.
Code:
<property name="createTs"         
          type="timestamp"
          column="CREATE_TS"  />
<property name="updateTs"
          type="timestamp"
          column="UPDATE_TS"  />


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 8:36 am 
Newbie

Joined: Fri Apr 28, 2006 1:48 pm
Posts: 7
My problem is the trigger doesn't populate UPDATE_TS column when the record is created and changing the trigger might be a problem at this moment. Can't have a new attribute to the generated attribute as "insert", "updated"? in addition to "generated" and "never"?

Regards,
Valy


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