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)

Postgres on Neon - Get the Free Plan

No credit card required. The database you love, on a serverless platform designed to help you build faster.

Get Postgres on Neon

AWS GenAI Live!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️