Reputation: 97
I am using hibernate's timestamp method to update the last_modified value whenever my row in the table is updated. Like this:
<timestamp name="lastModified" column="last_modified" />
I am using postgres db. When Hibernate updates the row, does it fire an SQL with now() or the plan vanilla date?
The reason is that I want it to use now() so the dates are consistent as then, database will assign the value not the appserver.
Upvotes: 4
Views: 703
Reputation: 133492
Using "timestamp" will make Hibernate use its idea of the current time, not the database's idea (this was correct as of Hibernate 3.0 and I doubt it's changed since).
If you want the column to receive database time, you can use a trigger to populate it on insert/update. If you want that generated time retrieved back by Hibernate, use a generated="always"
or generated="insert"
as appropriate (and demote the timestamp
element to a normal property
). Note this will produce additional select statements after update/inserts to retrieve the generated state.
Upvotes: 2