Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java hibernate中缺少@Temporal注释_Java_Hibernate_Jakarta Ee - Fatal编程技术网

Java hibernate中缺少@Temporal注释

Java hibernate中缺少@Temporal注释,java,hibernate,jakarta-ee,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() { retur

如果我们使用

@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
注释的日期列属性,是否有任何副作用?

我找到的唯一一个文档:

在普通Java API中,时间精度没有定义。在处理时态数据时,您可能希望描述数据库中的预期精度。时态数据可以具有日期、时间或时间戳精度(即实际日期、仅时间或两者)。使用@Temporal注释对其进行微调


这可能表明数据库中的实际日期表示形式没有定义,因此最好直接指定它。

我知道这个问题已经得到了回答,但我们今天仍在努力解决这个问题,因此我想为将来偶然发现这个问题的人提供一些更深入的见解

将Oracle 11g与version 11驱动程序一起使用如果不使用时态注释,那么Oracle中的每个日期、时间和时间戳数据类型都将在运行时映射到代码中的时间戳。从功能上来说,这很好,但是这给我们带来了严重的性能问题。这是因为我们有一个日期类型作为复合主键的一部分。该列是索引的前导列,也是我们用于分区的列。当驱动程序试图使用where子句中的此列持久化记录时,Oracle将对数据库中的数据执行从日期到时间戳的类型转换。这使得索引毫无用处,性能非常糟糕


说来话长,总是加上这个注释,以免你们准备付出代价

+1-我也没有找到更多的片段来讨论如果没有指定
@Temporal
时,Hibernate会做什么。正如一个加法-日食甚至不允许你不定义时间精度。我更愿意定义您期望的精确精度。我将在这个问题上添加一个与f:convertDateTime的比较。。。好的。用实时的例子很好的解释。泰!