我有一个实体,它有一个字段,我希望它是一个枚举。
@Column(name = "TEMPRATURE_ZONE")
@Enumerated(STRING)
private TemperatureRegime tempratureZone;Enum的定义如下:
public enum TemperatureRegime {
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)])我看不出有什么问题,有什么想法吗?
干杯,
詹姆斯
发布于 2010-07-30 00:29:20
我相信这只是一个案例问题。您的枚举定义了Chill,而数据库值为CHILL。最简单的解决方案应该是更改枚举定义以匹配数据库值。
或者,我记录了一种转换器方法来处理与枚举值不完全匹配的数据库字符串:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/EnumToCode
道格
https://stackoverflow.com/questions/3360400
复制相似问题