JPA @Enumerated 错误
我有一个实体,其中有一个字段,我想将其作为枚举。
@Column(name = "TEMPRATURE_ZONE")
@Enumerated(STRING)
private TemperatureRegime tempratureZone;
枚举定义如下:
public enum TemperatureRegime {
AMBIENT,
CHILL
}
我的表中该字段的数据始终为“AMBIENT”或“CHILL”,但是当我对表执行 findAll 查询时,出现以下异常:
Exception [EclipseLink-116] (Eclipse Persistence Services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: No conversion value provided for the value [Chill] in field [LOCATION_GROUP.TEMPRATURE_ZONE].
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[tempratureZone-->LOCATION_GROUP.TEMPRATURE_ZONE]
Descriptor: RelationalDescriptor(com.company.location.LocationGroup --> [DatabaseTable(LOCATION_GROUP)])
我看不出问题是什么,有什么想法吗?
干杯,
詹姆斯
I have a Entity with a field which I want to be an Enum.
@Column(name = "TEMPRATURE_ZONE")
@Enumerated(STRING)
private TemperatureRegime tempratureZone;
The Enum is defined as follows:
public enum TemperatureRegime {
AMBIENT,
CHILL
}
The data in my table for this field is always "AMBIENT" or "CHILL" yet when I do a findAll query on the table I am getting the following exception:
Exception [EclipseLink-116] (Eclipse Persistence Services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: No conversion value provided for the value [Chill] in field [LOCATION_GROUP.TEMPRATURE_ZONE].
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[tempratureZone-->LOCATION_GROUP.TEMPRATURE_ZONE]
Descriptor: RelationalDescriptor(com.company.location.LocationGroup --> [DatabaseTable(LOCATION_GROUP)])
I can't see what the problem is, any ideas?
Cheers,
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信这只是一个案例问题。您的枚举定义了 CHILL,而数据库值为 Chill。最简单的解决方案应该是更改枚举定义以匹配数据库值。
另外,我记录了一种转换器方法来处理与枚举值不完全匹配的数据库字符串:
http:// /wiki.eclipse.org/EclipseLink/Examples/JPA/EnumToCode
道格
I believe this is simply a case issue. Your enum defines CHILL while the database value is Chill. The simplest solution should be to change the enum definition to match the database values.
Alternatively I documented a converter approach to handle the database strings not matching the enum values exactly:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/EnumToCode
Doug