为什么有必要在javax.persistence中注释映射的Date字段@Temporal? [英] Why is it necessary to annotate mapped Date fields @Temporal in javax.persistence?

查看:148
本文介绍了为什么有必要在javax.persistence中注释映射的Date字段@Temporal?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

格式如下:

@Temporal(TemporalType.DATE)
@Column(name="CREATED_DATE")
private Date createdDate;

我的问题是:为什么需要注释映射的 java.util。 字段 @Temporal nofollow的> javax.persistence ?如果显然将局部变量声明为Date并且DB中的列数据类型也是日期(时间)或时间戳类型之一,则不应该很容易推断出我们正在处理数据的时间位没有在多个地方冗余地指定它?

My question is: Why is it necessary to annotate mapped java.util.Date fields as @Temporal in javax.persistence? If the local variable is obviously declared as a Date and the column data type in the DB is also one of the date(time) or timestamp types, shouldn't it be easy to infer that we're dealing with a temporal bit of data without redundantly specifying it in multiple places?

推荐答案

来自eg java.util.Date如果想要映射到DATE或TIMESTAMP数据库类型,那就不明显了。唯一的例外是java.sql.Date/Time。

From e.g. java.util.Date it's not obvious if one wants to map to DATE or TIMESTAMP database type. Only exception is java.sql.Date/Time.

这篇关于为什么有必要在javax.persistence中注释映射的Date字段@Temporal?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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