-->
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.  [ 4 posts ] 
Author Message
 Post subject: Custom user type to support last modified date
PostPosted: Wed Jan 05, 2005 8:28 pm 
Newbie

Joined: Wed Jan 05, 2005 8:20 pm
Posts: 10
I thought it may be possible to add a lastModifiedDate to my persistent objects using a custom UserType. I want to keep this as unobtrusive as possible so I chose UserType over an Hibernate session interceptor.

However, it is not working as I intended. I extended DateType and overrode the following method:

Code:
   public void set(PreparedStatement st, Object value, int index) throws SQLException {
      super.set(st, new java.util.Date(), index);
   }


a snippet of my mapping file is here:

Code:
<property
        name="lastUpdated"
        type="us.oh.state.dot.common.domain.type.UpdateTimestamp"
        column="LAST_UPDATED_DT"
        not-null="true"
/>


This would probably work, but Hibernate does not call set unless it detects the field is dirty. I thought I could override the isDirty check in the UserType but it seems isDirty is not called during the Session.save() call (Insert).

Anyone have any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 06, 2005 4:59 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Your can eiter use the <timestamp> tag which gives you optimistic locking as well.
Or you can set your property in the onFlushDirty method of an Interceptor.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 06, 2005 7:22 pm 
Newbie

Joined: Wed Jan 05, 2005 8:20 pm
Posts: 10
Quote:
Your can eiter use the <timestamp> tag which gives you optimistic locking as well.
Or you can set your property in the onFlushDirty method of an Interceptor.

Thanks for the help attempt. I mentioned the interceptor approach in my question, and the timestamp tag has a versioning implication that I don't want. (I use an integer value for versioning.)

There are *many* things I could do (include the property update in my DAO for example). I was wondering if it could be accomplished with a custom UserType? So far, I don't think it is possible because I can't force Hibernate to invoke my UserType if it doesn't think that my underlying property has been modified.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 07, 2005 3:01 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Guess you've set dynamic-update=true? Set it to false and hibernate sets all fields up on update.

AFAIK you cannot get this working only with a user type and have dynamic-update=true.

If you want to keep dynamic-update=true you must use an interceptor, set the filed in onFlushDirty or mark it as dirty in isDirty and set the value in a user type.

HTH
Ernst


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