在Hibernate中使用@Temporal注解是什么? [英] What is the use of the @Temporal annotation in Hibernate?

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

问题描述

Hibernate文档包含以下信息:
lock $ $
>在普通的Java API中,没有定义时间的时间精度。
在处理时态数据时,您可能想要描述数据库中
期望的精度。时间数据可以具有DATE,TIME或
TIMESTAMP精度(即实际日期,只有时间或两者)。使用
@Temporal注解来微调。


时间的时间精度是什么未定义是什么意思?什么是时间数据及其精度?它是如何微调的?

解决方案

必须为持久性字段或类型的属性指定此注释.util.Date java.util.Calendar 。它可能仅限于这些类型的字段或属性。



Temporal 注释可以与基本注释, Id 注释或 ElementCollection 注释(当元素集合值属于这种时间类型时)。

在普通的Java API中,时间的时间精度没有被定义,当处理时间数据时,可能需要描述数据库中的期望精度时态数据可以具有DATE,TIME或TIMESTAMP精度(即实际日期,只有时间或两者)使用 @Temporal

时间数据是与时间相关的数据,例如,在内容管理系统中,创建日期和最后一次数据可以在在某些情况下,时态数据需要精度,并且您希望将精确的日期/时间或两者都存储在数据库表中( TIMESTAMP ) 。



核心Java API中没有指定时间精度。 @Temporal 是一个在时间戳和 java.util之间来回转换的 JPA 注释。日期。它还将时间戳转换为时间。例如,在下面的代码片段中, @Temporal(TemporalType.DATE) 会删除时间值并仅保留日期。 em>

  @Temporal(TemporalType.DATE)
private java.util.Date creationDate;

根据javadocs,


注解在查询
方法参数上声明适当的{TemporalType}。请注意,此注释只能用于带有默认 TemporalType.DATE

的{blink Date}类型的
参数。

[以上各种来源收集的信息]


The Hibernate Documentation has the information below for the @Temporal annotation:

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.

What does temporal precision of time is not defined mean? What is temporal data and its precision? How does it fine tune?

解决方案

This annotation must be specified for persistent fields or properties of type java.util.Date and java.util.Calendar. It may only be specified for fields or properties of these types.

The Temporal annotation may be used in conjunction with the Basic annotation, the Id annotation, or the ElementCollection annotation (when the element collection value is of such a temporal type.

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 (i.e., the actual date, only the time, or both). Use the @Temporal annotation to fine tune that.

The temporal data is the data related to time. For example, in a content management system, the creation-date and last-updated date of an article are temporal data. In some cases, temporal data needs precision and you want to store precise date/time or both (TIMESTAMP) in database table.

The temporal precision is not specified in core Java APIs. @Temporal is a JPA annotation that converts back and forth between timestamp and java.util.Date. It also converts time-stamp into time. For example, in the snippet below, @Temporal(TemporalType.DATE) drops the time value and only preserves the date.

@Temporal(TemporalType.DATE)
private java.util.Date creationDate;

As per javadocs,

Annotation to declare an appropriate {@code TemporalType} on query method parameters. Note that this annotation can only be used on parameters of type {@link Date} with default TemporalType.DATE

[Information above collected from various sources]

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

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