File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Does �Hibernate� provide these features? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Does �Hibernate� provide these features?" Watch "Does �Hibernate� provide these features?" New topic
Author

Does �Hibernate� provide these features?

vinvinay jain
Greenhorn

Joined: Oct 28, 2004
Posts: 1
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
<timestamp
name="lastModifiedOn"
column="LAST_MODIFIED_ON"
/>
where �last_modified_on � is the column in the database used for versioning.
Created as
LAST_MODIFIED_ON DATE default SYSDATE;

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.
Or
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.
Regards
Vinay
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does �Hibernate� provide these features?