如果我们使用
@Column(name="birth_date", nullable=false, length=19)
public Date getBirthDate() {
return this.birthDate;
}
而不是
@Temporal(TemporalType.TIMESTAMP)
@Column(name="birth_date", nullable=false, length=19)
public Date getBirthDate() {
return this.birthDate;
}
如果我们使用不带@Temporal
注解的日期列属性会有副作用吗?
最佳答案
我只找到了一份文档:
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.
来自 2.2.2.1. Declaring basic property mappings .
这可能表明数据库中的实际日期表示尚未定义,因此最好直接指定它。
关于java - hibernate 中缺少@Temporal 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8473952/