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.
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 ]