什么是对于没有@MapKeyColumn或@MapKeyTemporal注释的时间映射键的默认TemporalType? [英] What's the default TemporalType for a temporal map key without a @MapKeyColumn or @MapKeyTemporal annotation?

查看:1208
本文介绍了什么是对于没有@MapKeyColumn或@MapKeyTemporal注释的时间映射键的默认TemporalType?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创造我的实习一个JPA 2.0注释合规性套件。
现在,我想知道当需要@MapKeyTemporal注释,当它是可选的...

I'm working on creating a JPA 2.0 Annotation compliancy kit for my internship. Right now, I'm wondering when a @MapKeyTemporal annotation is required and when it's optional...

我知道,当你使用定义的@MapKeyColumn地图键的列,该类型的按键应该映射到可以通过查看列(否则在columndefinition的类型)的类型的。因此,在这种情况下,没有@MapKeyTemporal注解是必要的。

I know that when you define the column of the map key using @MapKeyColumn, the type the key should be mapped to can be derived by looking at the type of the column (and otherwise the type in the columndefinition). Thus, in this case, no @MapKeyTemporal annotation is necessary.

当您连接@MapKeyTemporal注释,列名默认为定语+_key。

When you attach the @MapKeyTemporal annotation, the column name is defaulted to ATTRIBUTE + "_KEY".

当你不标注@MapKeyColumn和@MapKeyTemporal,列名默认为定语+_key,而是要什么类型的呢钥匙默认?或者是你应该得到一个错误?

When you don't annotate @MapKeyColumn and @MapKeyTemporal, the column name is defaulted to ATTRIBUTE + "_KEY", but to what type does the key default? Or are you supposed to get an error?

我找了一个类似的情况,发现@MapKeyEnumerated。
因为它涉及到@MapKeyColumn,它是一个可以映射到多个数据类型(值是相同的 java.sql.Date/java.sql.Time/java.sql.Timestamp 对于@MapKeyTemporal和 EnumeratedType.ORDINAL / EnumeratedType.STRING 为@MapKeyEnumerated)。
我发现一个区别:
@MapKeyEnumerated有一个默认。此默认为 EnumeratedType.ORDINAL

I looked for a similar situation and found @MapKeyEnumerated. It's the same because it's related to @MapKeyColumn and it's a value that can be mapped to multiple datatypes (java.sql.Date/java.sql.Time/java.sql.Timestamp for @MapKeyTemporal, and EnumeratedType.ORDINAL/EnumeratedType.STRING for @MapKeyEnumerated). I found one difference: @MapKeyEnumerated has a default. This default is EnumeratedType.ORDINAL.

我的问题:
当使用一个地图,有其基本类型是时间类型映射关键,什么是默认TemporalType(根据JPA 2.0),以该地图键转换为持久性?

My question: When using a map that has a map key whose basic type is a temporal type, what's the default TemporalType (according to JPA 2.0) to which the map key is converted for persistence?

推荐答案

答案似乎是,有当java.util.Date或java.util.Calendar中用作地图的键的默认类型。规范本身(我做考虑与规范交付规范的一部分的javadoc)是非常严格的MapKeyTemporal的使用。 Javadoc文档MapKeyTemporal称:

Answer seems to be, that there is no default type when java.util.Date or java.util.Calendar is used as key of the map. Specification itself (I do consider javadocs delivered with specification as part of specification) is very strict about usage of MapKeyTemporal. Javadoc for MapKeyTemporal claims:

这必须标注类型日期持续映射键被指定
  和日历。

This annotation must be specified for persistent map keys of type Date and Calendar.

我觉得这样的严格,他们忘记了您present,具有通过映射键引用的属性类型信息的情况下。它没有太大的意义来指定映射键的情况下类型,因为类型是在是地图的价值实体已经指定。还允许可能性具有用于在地图上的键不同的时间类型为实体对应字段是不可取的。

I think with such a strictness they forgot case that you present, having type information from attribute referenced by MapKey. It does not make too much sense to specify type in the case of MapKey, because type is already specified in the entity that is value of the map. Also allowing possibility to have different temporal type for key of the map for corresponding field in the entity is not desirable.

如果未指定MapKeyTemporal,如果没有其他的方法来找出关键的类型的EclipseLink(参考实现,但它并不总是以下规格)产生以下异常:

If MapKeyTemporal is not specified and if there is no other way to figure out type of the key, EclipseLink (reference implementation, though it is not always following specification) produces following exception:

org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute [map] from the entity class [class X]
does not specify a temporal type. A temporal type must be specified for persistent  
fields or properties of type java.util.Date and java.util.Calendar.
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:126)

这篇关于什么是对于没有@MapKeyColumn或@MapKeyTemporal注释的时间映射键的默认TemporalType?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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