Temporal annotation

Maven dependencies used all over JPA tutorials same. Please follow "Setting up Project" section to understand about project configuration.
persistence.xml and other code files reused from How to Persist an Entity in data base using JPA?
Each Sample application from download includes SQL file also.
  • @Temporal  annotation must be specified for persistent fields or properties of type java.util.Date and java.util.Calendar. It may only be specified for fields or properties of these types.

  • @Temporal annotation solves the one of the major issue of converting the date and time values from Java object to compatible database type and retrieving back to the application.
  • JPA supports  TemporalType.TIMESTAMPTemporalType.DATE, TemporalType.TIME.
  • These types are equivalent of   java.sql.Timestamp, java.sql.Datejava.sql.Time.

@Temporal Mapping Code Example :

  • From the above snippet line numbers 15,19,23 describes the mapping of Temporal type to the Entity.
  • @Temporal annotation more useful to convert specific type either TimeStamp or Time or Date.

Test Code :

Download Application – JPA-Temporal.zip (11 KB)