What is the proper way to create column type Datetime in MariaDB using Hibernate? I tried this:
@Column
@Type(type = "date")
@Temporal(TemporalType.DATE)
private Date created_at;
But I can't find a proper type in TemporalType for Datetime.
您需要使用TemporalType.TIMESTAMP作为DateTime。
This is what you need to do.
@Column
@Temporal(TemporalType.TIMESTAMP)
private Date created_at;
You don't need to write @Type(type = "date")
. And change your TemporalType
to TimeStamp
. So finally your code will be like this;
@Column
@Temporal(TemporalType.TIMESTAMP)
private Date created_at;
PS: You don't need to write @Column
tag.
Use the columnDefinition attribute of the @Column annotation:
@Column(name = "startTime", columnDefinition="DATETIME")
@Temporal(TemporalType.TIMESTAMP)
private Date startTime;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.