-->
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.  [ 7 posts ] 
Author Message
 Post subject: auto Update timestamp field
PostPosted: Tue Oct 23, 2007 2:04 am 
Newbie

Joined: Fri Aug 31, 2007 11:58 am
Posts: 19
Hi , i am having a Date field which needs to be updated with current time stamp whenever any update is invoked on the row.

Its not for version control as i am handling this with another field.Its just that user needs to be aware of last update time.

so my code is somewhat like



Code:
@Version @Column( name="obj_version",nullable=false )
private int version = 0;

@Temporal( TemporalType.TIMESTAMP )
@Column( columnDefinition="Timestamp default sysdate", nullable=false )
@org.hibernate.annotations.Generated(org.hibernate.annotations.GenerationTime.ALWAYS)
private Date update_date;



this is not working ,update date is only generated at the time of insert but no further updates.

So update_date only shows creation date.

Thanks for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 23, 2007 2:54 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you need some trigger in your column database.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 24, 2007 3:19 am 
Newbie

Joined: Fri Aug 31, 2007 11:58 am
Posts: 19
Is that means
@org.hibernate.annotations.Generated(org.hibernate.annotations.GenerationTime.ALWAYS)

works only for @Version

_________________
Note:Don't forget to rate,if useful.

Blog:http://elope.wordpress.com/


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 29, 2007 4:05 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no it means that the value will be read from the database rather than inserted or updated.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 31, 2007 8:02 am 
Newbie

Joined: Fri Aug 31, 2007 11:58 am
Posts: 19
Hi ,
I am somewhat confused.

If i write a trigger in DB than what is the use of
@org.hibernate.annotations.Generated(org.hibernate.annotations.GenerationTime.ALWAYS)

Can you please point me to some example where this annotation is being used , not for version purpose i.e not with @Version.

thanks a lot.

_________________
Note:Don't forget to rate,if useful.

Blog:http://elope.wordpress.com/


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 31, 2007 11:03 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
As far as I know, @org.hibernate.annotations.Generated(org.hibernate.annotations.GenerationTime.ALWAYS) specifies that the property will not be inserted or updated from the object, instead it will read the value for the property from db through a subsequent select. Thats my opinion. may be I am wrong in my comprehension of things.

For updating the value in your column, you can either use a trigger (as suggested in earlier post) or you can make use of interceptor / event listener to get the job done.

HTH

_________________
Please rate this post if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 31, 2007 5:19 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
sethrohit1977 wrote:
As far as I know, @org.hibernate.annotations.Generated(org.hibernate.annotations.GenerationTime.ALWAYS) specifies that the property will not be inserted or updated from the object, instead it will read the value for the property from db through a subsequent select. Thats my opinion. may be I am wrong in my comprehension of things.


You are correct, the value is generated :)

_________________
Emmanuel


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