Reputation: 18511
In my sql there are the following date types: Date ,Time,Year, Datetime, timestamp.
my class holds a date object. How can I choose which type should be created in the DB?
Upvotes: 4
Views: 8148
Reputation: 16035
You can mark the Date-object with @Temporal-annotation:
In plain Java APIs, the temporal precision of time is not defined. When dealing with temporal data you might want to describe the expected precision in database. Temporal data can have DATE, TIME, or TIMESTAMP precision (ie the actual date, only the time, or both). Use the @Temporal annotation to fine tune that.
@Temporal(TemporalType.TIMESTAMP)
private Date someDate;
Upvotes: 7