@Enumerated(EnumType.STRING) causes No conversion value provided for the value [0]

7.3k Views Asked by At

I have used this all the time, but now it's no longer working. Really strange. Code snippet:

@Column(name = "STAT", length = 16)
@Enumerated(EnumType.STRING)
private State state = State.LIVE;

...

public enum State {
    LIVE,
    DELETED;
}

In the db, there are only values stored with LIVE or DELETED. No nulls.

But i'm getting: Exception [EclipseLink-116] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.DescriptorException Exception Description: No conversion value provided for the value [0] in field [WERK.STAT]. Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[state-->WERK.STAT]

It seems to me, that the ordinal ('...provided for the value [0]...') comes - somehow - into place, but i don't know why and how to get rid of it.

I'm using glassfish 3.1.2 which uses eclipselink 2.3.2. I upgraded to eclipselink 2.4.2 with the same result. It's weird, because it's running on my development machine without any problems. I'm using mysql 5.6.14.

Thx

Got it. The exception text is finally wrong. I found that [0] value, but in a completely different table (which has no reference to WERK at all) and has been imported using an sql script containing these [0] values (my fault). So, if you have ever a similar problem you have to check the whole database content, not just those mentioned.

3

There are 3 best solutions below

0
On

The error resides on the DB query, make a query and find if the enums values match with the properties in the enum class, if not then make an adjustment into the Database if this is possible, and if not maybe you could find what are the values for your enum properties.

Might be an error in the database values or fine, the number of values differs from the values that you need to validate.

public enum State {
    LIVE,
    DELETED;
}

select distinct(state) from WERK;

this should devolve only to those two values that you are enum (LIVE,EDIT). If not that is the cause of your problem.

0
On

this error commnig if the enumeration column does not mach the value of column in the database, example: you defin in the database table status with column name {status1, status2, status3, status4} represent the java enum, and the enums status{status1, status2, status3} in this case the status1, status2 and status3 match values in the database, but the status4 does not match any value(does not exist), in this case this error will appear.

0
On

In my case, I have modified the table with another application allowing null values in all fields (except the primary key of course) . And when I return to my first application (which runs fine initially) I got this exception. So I truncate (delete all the rows in the table) and the application runs fine now.