Categories
Java Oracle

Mapping Hibernate to Oracle Date fields

Sometimes less is more.
We are using Hibernate and one of the tables uses a Date field to store information on what Oracle calls ‘point in time’ – the date and time of an event. The table column was mapped to an object property specifying the property type as “date”. For some reason, that caused the application to only read and write the date part of the ‘point in time’ instead of both the date and the time.
Example:
<property name=”postDate” column=”POST_DATE” not-null=”true” type=”date” />
Thanks to the last comment in this post, I found out that if you remove the explicit type from the Hibernate mapping, the table will be read and written to with both the date and the time.
Example:
<property name=”postDate” column=”POST_DATE” not-null=”true”/>

Share
Share