开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜