-->
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: Automatically update "LAST-MODIFIED" field
PostPosted: Sat Dec 27, 2008 11:58 am 
Newbie

Joined: Tue May 06, 2008 4:19 am
Posts: 6
Hibernate version:3.3.2

Name and version of the database you are using:MySQL 5

Hi guys,

I am using Hibernate JPA, I want to know is that possible to automatically update a field with the current time via JPA annotation? I guess JPA SPEC does not cover this but I still want to know if anybody has work arounds if annotation can not help.

Let's say I have a table PERSON with a column named "last-modified", it's a DATETIME field for time stamp purpose, each time I load the entity, eg,

Person p = entityManager.find(Person.class, 1);

I modify it a little bit, eg, p.setAge(20);

Then merge back to database, eg, em.merge(p);

If I want to update "last-modifed" column I have to "manually" call p.setLastModified(new Date()) each time I change the entity. So is that possible to do that automatically? I mean the Hibernate framework detects if the entity has been modified, if not, simply not update database, if yes, updates the timestamp field "last-modified" automatically and flushes back to database?


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.