在hibernate中没有@Temporal注解 [英] Absence of @Temporal annotation in hibernate

查看:295
本文介绍了在hibernate中没有@Temporal注解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们使用

  @Column(name =birth_date,nullable = false,length = 19) $ b public Date getBirthDate(){
return this.birthDate;
}

而不是

 @Temporal(TemporalType.TIMESTAMP)
@Column(name =birth_date,nullable = false,length = 19)
public Date getBirthDate(){
返回this.birthDate;



$ b $ p
$ b如果我们使用日期列属性而没有任何副作用 @Temporal 注解?

解决方案

>


在普通Java API中,时间精确度未定义。在处理时态数据时,您可能想要描述数据库中的预期精度。时间数据可以具有DATE,TIME或TIMESTAMP精度(即实际日期,仅时间或两者)。使用@Temporal注释来微调。


From 2.2.2.1。声明基本的属性映射



这个 may 表示数据库中的实际日期表示没有被定义,并且确定它最好直接指定它。


What if we use

@Column(name="birth_date", nullable=false, length=19)
public Date getBirthDate() {
    return this.birthDate;
}

instead of

@Temporal(TemporalType.TIMESTAMP)
@Column(name="birth_date", nullable=false, length=19)
public Date getBirthDate() {
    return this.birthDate;
}

Are there any side effects if we use date column property without @Temporal annotation?

解决方案

Only piece of documentation I managed to find:

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.

From 2.2.2.1. Declaring basic property mappings.

This might indicate that the actual date representation in the database is not defined and to be sure it is better to specify it directly.

这篇关于在hibernate中没有@Temporal注解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆