• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Does �Hibernate� provide these features?

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

We are using Hibernate for our Web Based Application, we have come up with few issues:

The application has a multi-tier architecture with struts for the presentation layer and hibernate as the persistence layer. The application also involves stateless session beans in the business tier. The database used is Oracle 9i and the application server is WAS 5.1.

Issue 1::-- We are using the �Timestamp� strategy for Optimistic Locking,
We are using a timestamp based column for versioning. This column stores the date (database date) for a record when the record is modified by any user.
Its specified as
where �last_modified_on � is the column in the database used for versioning.
Created as

The issue we are facing is that when we try and update a record hibernate updates the �last_modified_on� column with �System date� of the Application Server instead of �Database Server Date�.
The column by default would apply the database �sysdate� if no value were specified in the update statement.
If it was possible to have update=�false� and insert=�false� for the timestamp attribute it would�ve solved the problem.
How do we ensure that the database server date is taken for updation instead of the application server date.
How do we ensure that the last_modified_on column is not considered for updation? In which case the database server date returned by �sysdate� would be applied and stored for that column.

Issue 2::-- Does hibernate provide any functionality where we can modify the Date format, say if we want to enter "Time" along with the Date while retrieving / persisting data?

To find the solution to this issues we have left no stone unturned, now only you can tell us weather �Hibernate� provides solution to problems like this.

Waiting for your reply.
Posts: 17346
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is almost like you shouldn't map that field.

What about an update trigger on the database that automatically sets this field to the Data Servers time regardless of what is passed in the update statement?

Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is why I've always used a version number column for optimistic locking, just as the Hibernate team recommends. True, you don't always have the choice, but doing so in this case would solve your problem.

At first it seems using an update trigger could solve the issue, but Hibernate would need to read the new value after doing an insert/update. This is very similar to the problem of generating IDs using a database sequence. It would be wonderful if you could retrieve data at the same time you do an insert/update. Alas, that's just not an option unless you use stored procedures.

Is Hibernate the only code that accesses your database? If so, you could let Hibernate manage the timestamps entirely. In other words, remove the default from the column and let all timestamps be created by Hibernate.
[ October 29, 2004: Message edited by: David Harkness ]
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic