5

I have similar problem like this [Hibernate Exception: Unknown name value for enum class

But in my case,

Unable to filter, so returning non filtered results.Unknown name value for enum class com.xxxx.enums.Status: DELIVERED
java.lang.IllegalArgumentException: Unknown name value for enum class com.xxxx.enums.Status: DELIVERED
    at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:128)
    at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:109)
    at org.hibernate.type.AbstractType.hydrate(AbstractType.java:104)


@Enumerated(value = EnumType.STRING)
@Column(name = "status", length = 10)
@AuditableField
private Status status;

public enum ReleaseStatus {
     DL("Delivered"),
}

Everything seems fine, still I am getting that exception.

4
  • Could it be that your enum field is called DL and not DELIVERED? Commented Jun 21, 2014 at 5:46
  • @beerbajay, if you look at the other so post, no issue with being defined as 'DL' Commented Jun 21, 2014 at 6:10
  • I mean that there's a mismatch between the two names. Just try it. Commented Jun 21, 2014 at 6:11
  • @beerbajay, not possible :( as some other dependencies on that enum. Commented Jun 21, 2014 at 6:15

2 Answers 2

11

You have the String DELIVERED in your table. And this string is supposed to be the name() of one of the ReleaseStatus instances. And ReleaseStatus doesn't have any instance named DELIVERED. The only one you posted is named DL.

So what should be in the table is DL not DELIVERED. Or you should rename your enum instance to DELIVERED, to match what is stored in the database table.

You could define a custom Hibernate user type and use it for this enum as well, so that when getting "DELIVERED" from the database, Hibernate finds the enum instance constructed with this value (and ignoring the case). But storing the correct value from the start looks like a betteridea to me.

Sign up to request clarification or add additional context in comments.

Comments

10

I prefer defining a custom converter like:

    @Column
    @Convert(converter = StatusFirmaDocumentoConverter.class)  <<<<< :)
    @AuditableField
    private Status status;

(note: do not include the @Enumerated attribute) and creating a converter to process the enumerator value like:

public class CustomConverter implements AttributeConverter<Status, String> {

    @Override
    public String convertToDatabaseColumn(Status attribute) {
        return attribute.getValue() ;
    }

    @Override
    public Status convertToEntityAttribute(String dbData) {
        return  StatusFirmaDocumento.fromString(dbData);
    }

}

yeah, it's a shame that you can't tell to hibernate "translate DL to DELIVERED" and viceversa

1 Comment

Might be useful for someone else, but I left the Enumerated with the Convert and hibernate ignored the converter. Make sure to only have the Convert!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.