-->
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.  [ 1 post ] 
Author Message
 Post subject: Maintaining record "last updated time"
PostPosted: Wed Jul 08, 2009 12:17 pm 
Beginner
Beginner

Joined: Thu May 28, 2009 10:25 am
Posts: 21
This post below talks about the issue a bit but I'd like to confirm whether I can have Hibernate automatically update "last update time" whenever a record is updated, or does is the responsibility of the underlying db.

All I want to do is elegantly record the update time of a record.

viewtopic.php?t=986972&highlight=

Quoting from Gavin King's book : "Java Persistance with Hibernate"

Quote:
Typically, Hibernate applications need to refresh objects that contain any
properties for which the database generates values. Marking properties as gener-
ated, however, lets the application delegate this responsibility to Hibernate. Essen-
tially, whenever Hibernate issues an SQL INSERT or UPDATE for an entity that has
defined generated properties, it immediately does a SELECT afterwards to retrieve
the generated values. Use the generated switch on a property mapping to enable
this automatic refresh:
<property name="lastModified"
column="LAST_MODIFIED"
update="false"
insert="false"
generated="always"/>

.
.
With annotations, declare immutability (and automatic refresh) with the
@Generated Hibernate annotation:
@Column(updatable = false, insertable = false)
@org.hibernate.annotations.Generated(
org.hibernate.annotations.GenerationTime.ALWAYS
)
private Date lastModified;



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.