2

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

James
  • 3,597
  • 11
  • 47
  • 57
  • Naming choice: `TemperatureRegime` (I'm pointing at "regime") is maybe not want you mean here. Properly take `TemperatureZone` or `TemperatureRegion`. Sure this doesn't answer your question, but gives your code a bit more clear what your enumeration is all about and temperated regimes are properly not what you mean ... – Roland Nov 18 '17 at 16:09

1 Answers1

8

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

Doug Clarke
  • 550
  • 2
  • 6
  • Also I would recommend to check the mapping of data in DB with enum. I've faced the same issue and the reason was just missing enum field which I tried to get from the DB. – excelsiorious Mar 04 '21 at 14:14