• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate generate timestamp on create and update

 
Anand Loni
Ranch Hand
Posts: 150
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nikita Protsenko
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 150
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I remove updatable and insertable fields, I am getting below error while deploying...



 
Nikita Protsenko
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 150
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nikita,

Thanks for the reply.

I did the things you mentioned..but its not working for me
 
Nikita Protsenko
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 150
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 150
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic