GeeCON Prague 2014*
The moose likes Object Relational Mapping and the fly likes Hibernate generate timestamp on create and update Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate generate timestamp on create and update" Watch "Hibernate generate timestamp on create and update" New topic
Author

Hibernate generate timestamp on create and update

Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
Hi,

I am using hibernate/JPA annotations. I need to have two fields creation time and modified time in the table which will be updated by hibernate. I tried using @generated, but its not updating the fields. Any other simple approach to update the fields automatically.



Thanks in advance.


~ Anand,
SCJP 1.5, SCWCD 1.5
Nikita Protsenko
Greenhorn

Joined: May 03, 2010
Posts: 5
I assume that the following clause gets in the way: "updatable = false, insertable = false". I think it stops the Hibernate from writing these fields into the database.
Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
If I remove updatable and insertable fields, I am getting below error while deploying...



Nikita Protsenko
Greenhorn

Joined: May 03, 2010
Posts: 5
The following works for me:



I am using Hibernate/JPA too. I've skipped the @Generated annotation, though.

Here is the test code:



...and the output:


Everything seems to be working. Hope that'll help you.
Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
Hi Nikita,

Thanks for the reply.

I did the things you mentioned..but its not working for me
Nikita Protsenko
Greenhorn

Joined: May 03, 2010
Posts: 5
Hello, Anand!

I've found that there was a bug in some versions of Hibernate that looks very similar to your problem.

Link to the JIRA page

Which version of Hibernate do you use? I am using 3.5.1-Final. Maybe it is a root of the problem?

Best regards,
Nikita Protsenko
Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
Hi Nikita,

Thanks for the reply.

I m using hibernate v 3.2.5. I will updates jars from 3.5.0 and will check.

Thanks Again,
Anand Loni
Ranch Hand

Joined: Jan 20, 2006
Posts: 150
Hi,

Now I am using Hibernate v3.5.0 jars, but I am not able to deploy war to my weblogic server.

I am getting below error



I googled for this error..but I am not able to solve it. >
Nikita Protsenko
Greenhorn

Joined: May 03, 2010
Posts: 5
It seems like you are using JPA 2.0 in the compile time, but your appserver provides only JPA 1.0 in the runtime. Here is a couple of links that may give you a clue about the error:

http://opensource.atlassian.com/projects/hibernate/browse/HHH-4955
http://stackoverflow.com/questions/2511997/i-am-getting-an-error-with-a-onetomany-association-when-using-annotations-with-gi

The prospect looks gloomy, though.
 
GeeCON Prague 2014
 
subject: Hibernate generate timestamp on create and update