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?
|