Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map MySQL Timestamp field in Spring JAVA(JPA/Hibernate)

I am having trouble finding how to map different type of fields for different DBs in a Spring Boot Application. Primarily, I would like to know how to map the MySQL Timestamp but it would be great if I can also find a link to the collection of mappings for every datatype in different DBs.

like image 555
Abhay Avatar asked Dec 06 '25 04:12

Abhay


1 Answers

The list of standard basic types you can find here.

  1. You can map TIMESTAMP to the following Java 8 types:

java.time.Instant, java.time.LocalDateTime, java.time.OffsetDateTime and java.time.ZonedDateTime.

  1. You can also use outdated java.util.Date (see this):
@Column(name = "`timestamp`")
@Temporal(TemporalType.TIMESTAMP)
private Date timestamp;

But the first approach is much more preferable.

like image 101
SternK Avatar answered Dec 07 '25 18:12

SternK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!