This week's book giveaways are in the Angular and TypeScript and Web Services forums.
We're giving away four copies each of Programming with Types and The Design of Web APIs and have the authors on-line!
See this thread and this one for details.
Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Hibernate generate timestamp on create and update

 
Ranch Hand
Posts: 150
  • 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.
 
Greenhorn
Posts: 5
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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 found a beautiful pie. And a tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!