我得到了下面的堆棧跟蹤 線程「main」中的異常java.lang.IllegalArgumentException:枚舉類的未知名稱值[NC-17] [com.ecw.pojo.Rating] at org.hibernate.type.EnumType $ NamedEnumValueMapper.fromName(EnumType.java:467) at org.hibernate.type.EnumType $ NamedEnumValueMapper.getValue(EnumType.java:452) at org.hibernate.type.EnumType.nullSafeGet( EnumType.java:107) at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:127) at org.hibernate.type.AbstractType.hydrate(AbstractType.java:106) at org.hibernate.persister。 entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2969) at org.hibe (org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1627) at org.hibernate.loader.Loader.getRow(Loader.java:1514)org.hibernate.loader.load() at org.hibernate.loader.getRowFromResultSet(Loader.java:725) at org.hibernate.loader.Loader.processResultSet(Loader.java:952) at 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) at org.hibernate.loader.collection.plan.LegacyBatchingCollectionInitializerBuilder $ LegacyBatch ingCollectionInitializer.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) 在org.hibernate.collection.internal.AbstractPersistentCollection $ 4.doWork(AbstractPersistentCollection.java:555) 在org.hibernate.collection.internal.AbstractPersistentCollection .withTemporarySessionIfNeeded(AbstractPersistentCollection.java:260) at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:551) at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:140) at org.hibernate.collection.internal.PersistentSet.toString(PersistentSet.java:316) at 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;
你能幫我怎麼創建它嗎?如果有任何例子,然後發送給我的鏈接。感謝您的快速回復@JB Nizet – Sunny
谷歌「JPA屬性轉換器」,點擊第一個鏈接,然後閱讀。然後嘗試將示例適用於您的特定情況。 –