DEV Community

Tommy
Tommy

Posted on • Updated on

Hibernate - @Temporal

Temporal Annotation

The @Temporal is a Hibernate JPA annotation that is used for java.util.Date or java.util.Calendar. It converts the date and time values into a compatible format when storing or retrieving from a database. When handling temporal data remember to define the expected precision in the database. Temporal data precision can have DATE, TIME, or TIMESTAMP.

Example

@Temporal(TemporalType.TIMESTAMP)
@Column(name="DATETIME_COL")
public Date dateAndTime;

@Temporal(TemporalType.TIMESTAMP) 
@Column(name="TIMESTAMP_COL") 
public Date timeStamp;

@Temporal(TemporalType.DATE) 
@Column(name="DATE_COL")  
public Date date;

@Temporal(TemporalType.TIME) 
@Column(name="TIME_COL")  
public Date time;
Enter fullscreen mode Exit fullscreen mode

Discussion (0)