Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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.
 
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic