I'm trying to persist a Date object in Hibernate with millisecond precision.
private Date date = new Date();
@Column(columnDefinition="DATETIME(3)")
public Date getDate() {
return date;
}
But in the database the millisecond component is always .000. Is it simply not possible to store a Date object with millisecond precision using Hibernate?
java.util.date will only persist down to the second, since this is mapped to an SQL DATE type by the ORM, which may not contain milliseconds (at least in implementations I'm familiar with).
java.sql.timestamp supports fractional seconds.
I would definitely look into using the new Java 8 date libraries if you're able (or joda if you can't use Java 8). They're much better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With