java hibernate - how do i map a date column as datetime?
In my sql there are the following date types: Date ,Time,Year, Datetime, timestamp.
my class holds a d开发者_如何学JAVAate object. How can I choose which type should be created in the DB?
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;
精彩评论