DEV Community

Tommy
Tommy

Posted on • Edited on

4 4

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

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay