Question

I am getting started with Hibernate, and I am getting the following error for an entity which is supposed to have an enum type.

java.lang.IllegalArgumentException: No enum const class app.entity.ObjType.
java.lang.Enum.valueOf(Enum.java:214)
    org.hibernate.type.EnumType.nullSafeGet(EnumType.java:125)
    org.hibernate.type.CustomType.nullSafeGet(CustomType.java:109)
    org.hibernate.type.AbstractType.hydrate(AbstractType.java:104)
    org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2283)

I have the following enum type defined:

package app.entity;

@Entity
class Example {
    @Enumerated(EnumType.STRING)
    private ObjType type;
}

And the defined Enum class is as follows:

package app.entity;

public enum ObjType {
    typeA,
    typeB
}

What am I doing wrong? Also do set and get methods also have to be annotated with "@Enumerated(EnumType.STRING)" ?

I would appreciate any help. Thanks

Was it helpful?

Solution

I think you have an empty value in the database which it is trying to load and it can't find an enum value for the empty value. Note the extra . at the end of the error message

app.entity.ObjType.

where it has tried to concat "" with the enum class.

OTHER TIPS

It looks pretty close. Try Using uppercase names for your Enum values to start with. Here's a similar post that may also help. It talks about Hibernate 3.2+ being required.

Enumerations in Hibernate

Come back if its still not clear

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top