java - hibernate 中缺少@Temporal 注释

标签 java hibernate jakarta-ee

如果我们使用

@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/

相关文章:

java - Java中检测处理器数量的平台无关方式

java - hibernate 4 : saveOrUpdate exception

mysql - 外键 BIGSERIAL NULL Postgres

java - 无法实例化类 : com. sun.enterprise.naming.SerialInitContextFactory

java - 带按钮的滑动菜单

java - 没有&符号的改造查询

java - 无法从 Java 代码连接 Clamd 服务器(Ubuntu)

java - hibernate 默认采用哪种命名策略

java - Glassfish 服务器中的记录器错误

java - Hibernate @ManyToMany 与复合键的映射