Tuesday, December 4, 2012

Issues with persisting Date | Hibernate - Annotations

Very recently I came across a situation where in the Date that was being persisted into the database was saving the Date correctly but the Time was being saved as “00:00:00”.

·         Hibernate – Annotated
·         Oracle 11g

The issue was resolved by changing the value of the TemporalType Enum in the @Temporal annotation carried by the getter of the respective attribute in the domain object from TemporalType.DATE to TemporalType.TIMESTAMP.

The annotation @Temporal must be specified for persistent fields of type java.util.Date and java.util.Calendar. It may be used only for fields of these types. This annotation can be used in conjunction with the other basic annotations like Id.

No comments:

Post a Comment