JPA @Enumerated Error
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 follow开发者_高级运维s:
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
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
精彩评论