枚举类的未知名称值[]



我在stacktrace下面java.lang.IllegalArgumentException:枚举类[com.ecw.pojo.Rating]的未知名称值[NC-17]org.hibernate.type.EnumType NamedEnumValueMapper.fromName美元(EnumType.java: 467)org.hibernate.type.EnumType NamedEnumValueMapper.getValue美元(EnumType.java: 452)org.hibernate.type.EnumType.nullSafeGet (EnumType.java: 107)org.hibernate.type.CustomType.nullSafeGet (CustomType.java: 127)org.hibernate.type.AbstractType.hydrate (AbstractType.java: 106)org.hibernate.persister.entity.AbstractEntityPersister.hydrate (AbstractEntityPersister.java: 2969)org.hibernate.loader.Loader.loadFromResultSet (Loader.java: 1695)org.hibernate.loader.Loader.instanceNotYetLoaded (Loader.java: 1627)org.hibernate.loader.Loader.getRow (Loader.java: 1514)org.hibernate.loader.Loader.getRowFromResultSet (Loader.java: 725)org.hibernate.loader.Loader.processResultSet (Loader.java: 952)org.hibernate.loader.Loader.doQuery (Loader.java: 920)org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections (Loader.java: 354)org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections (Loader.java: 324)org.hibernate.loader.Loader.loadCollection (Loader.java: 2263)org.hibernate.loader.collection.plan.LegacyBatchingCollectionInitializerBuilder LegacyBatchingCollectionInitializer.initialize美元(LegacyBatchingCollectionInitializerBuilder.java: 105)org.hibernate.persister.collection.AbstractCollectionPersister.initialize (AbstractCollectionPersister.java: 693)org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection (DefaultInitializeCollectionEventListener.java: 92)org.hibernate.internal.SessionImpl.initializeCollection (SessionImpl.java: 1893)在4.美元org.hibernate.collection.internal.AbstractPersistentCollection dowork (AbstractPersistentCollection.java: 555)org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded (AbstractPersistentCollection.java: 260)org.hibernate.collection.internal.AbstractPersistentCollection.initialize (AbstractPersistentCollection.java: 551)org.hibernate.collection.internal.AbstractPersistentCollection.read (AbstractPersistentCollection.java: 140)org.hibernate.collection.internal.PersistentSet.toString (PersistentSet.java: 316)java.lang.String.valueOf (String.java: 2994)java.io.PrintStream.println (PrintStream.java: 821)util.TestMapping.main (TestMapping.java: 35)

My enum class as below
public enum Rating {
    G("G"),
    PG("PG"),
    PG13("PG-13"),
    R("R"),
    NC17("NC-17");
    private String value;
    private Rating(String value) {
        this.value = value;
    }
    public String getValue() {
        return value;
    }
    public void setValue(String value) {
        this.value = value;
    }
    public String toString() {
        return this.value; //will return , or ' instead of COMMA or APOSTROPHE
    }
}

和实体如下

@Column(name = "rating")
@Enumerated(EnumType.STRING)
private Rating rating;

Hibernate不关心您的自定义值属性。使用enum的名称:NC17,而不是NC-17

如果你想使用NC-17,你需要一个Hibernate自定义类型的JPA属性转换器

相关内容

  • 没有找到相关文章

最新更新