-->
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: Automatically update timestamp
PostPosted: Thu Oct 21, 2004 5:21 am 
Newbie

Joined: Tue Oct 05, 2004 4:56 am
Posts: 7
Hi all,

I've got a field for the last changed timestamp (LAST_CHG_TMS) in a lot of the tables i should map with Hibernate and I'm searching for a solution to do this update automatically.

I thought of implementing a UserType which does ignore the value given for setValue and set the system date instead but this seems to be the wrong path. Since this field can be null Hibernate will not call my method if i do not explicit update this field.

Another solution i thought of was using the <timestamp> element but as far as i understood this is used in combination with versioning, which i don't want to have.

Any ideas or hints?


thx
Roman


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 21, 2004 7:08 am 
Newbie

Joined: Tue Jul 06, 2004 9:56 am
Posts: 14
Another solution would be using triggers. Probably even faster, yet it can be DB specific.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 21, 2004 7:12 am 
Newbie

Joined: Tue Oct 05, 2004 4:56 am
Posts: 7
The problem is that i don't want this to be database specific. That's why we started the whole Hibernate usage, to get a business object model which is no longer depended on the database we use. I still hope to find a solution how to automatically update the timestamp (especially since i should insert the database time and not the time from the webserver).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 21, 2004 11:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Another way would be an Interceptor implementation.

BTW, a <timestamp/> really is just a type in the Hibernate type system; so it is essentially the same as your UserType idea (version and timestamp just happen to be "special" and have additional semantics).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 08, 2004 7:17 am 
Newbie

Joined: Tue Oct 05, 2004 4:56 am
Posts: 7
I've gone for the Interceptor solution which works really well for my purpose. Or let's say it worked well until now. The problem i have is that the interceptors onSave and onFlushDirty methods are not called for composite elements.

I have a list of log entries in one of my classes which i mapped as list with a composite element:

<list name="LogEntries" lazy="true" table="FT_T_PLOG">
<key column="PBLM_OID"/>
<index column="LN_NUM" type="integer"/>
<composite-element class="com.ftisoft.exceptionmgmt.ProblemLogEntry">
<property name="lastChangedTimestamp" type="timestamp" column="LAST_CHG_TMS"/>
<property name="lastChangedUserId" type="string" column="LAST_CHG_USR_ID"/>
<property name="commentReason" type="string" column="CMNT_REAS_TYP"/>
<property name="commentText" type="string" column="COMM_TXT"/>
</composite-element>
</list>

The interceptor is called for the main class but not for ProblemLogEntry class.

Any ideas?


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.