I am trying to have certain values created/updated when a new record
is created or an existing one is updated. I'm using the following
field (using hibernate annotations as demonstrated in Hibernate In
Action):
@Column(updatable = false, insertable = false)
@org.hibernate.annotations.Generated(
org.hibernate.annotations.GenerationTime.INSERT
)
private Date created;
Its simple; all I want is the 'created' field to be provided by
hibernate as a timestamp for when it was created. Similarly, I want a
timestamp field (named 'modified') to be updated whenever the record
is changed. For that I have:
@Column(updatable = false, insertable = false)
@org.hibernate.annotations.Generated(
org.hibernate.annotations.GenerationTime.ALWAYS
)
private Date modified;
Unfortunately neither of these work. From the book as well as other
documentation (the website), I can't see that I'm doing anything
incorrectly, but the behavior I'm getting is that both of these fields
are always null. Can anyone see what I've done wrong (or not doing)?
Sincerely,
Chris
Good luck,
Daniel.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
"Cannot have @Generated property and insertable columns: ..." - so it
appears that you must use insertable=false with @Generated, and the
book (Hibernate In Action) states this as well. However it doesn't
work as the book says it should, unless I'm just misunderstanding it.
I know hibernate can do this - its a simple operation - I just can't
figure out how...
On Oct 22, 4:50 pm, Daniel Pitts
Hi,
Can you give an example of the time value being created?
Complete prototype of the time structure would be helpful.
I'm using MySQL 5x, for which the DATETIME format is 'YYYY-MM-DD
HH:MM:SS'.
Thanks for any input!
Chris. Have you found out what the issue is with @Generated using a
create/modify timestamp? I am experiencing the exact-same thing you
are. All the examples and docs make it seem so cut-'n-dry... thus, I
cannot figure out what is going wrong.
Thanks!
--Josh
I am also having this problem and would be interested to hear an
answer if anyone has got it
I filed a bug on this in June, but have received zero response
from anybody at Hibernate. See
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2511
Maybe if you would visit the bug and add your examples it might
get a little visibility.