Hi
I am trying to use enum type in one of my entities, but when I try to get the object, Hibnernate tells me there is an unknown name value for the enum type. Please help. Thanks.
Code:
@Entity
public class CreditCard {
@Enumerated(EnumType.STRING)
@Column(name = "type", nullable = false)
private CreditCardType type;
...
}
Code:
public enum CreditCardType {
MASTERCARD("Mastercard"),
VISA("Visa"),
AMEX("American Express");
private final String cardType;
private CreditCardType(String cardType) {
this.cardType = cardType;
}
public String toString() {
return cardType;
}
}
Hibernate version: 3.2.3.ga
Name and version of the database you are using: PostgreSQL 8.2
Full stack trace of any exception that occurs:Code:
java.lang.IllegalArgumentException: Unknown name value for enum class auction.model.CreditCardType: String
at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:104)
at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:105)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2046)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1371)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1299)
at org.hibernate.loader.Loader.getRow(Loader.java:1197)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:568)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1985)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:109)
at org.hibernate.collection.PersistentBag.size(PersistentBag.java:225)
at auction.dao.CreditCardDAOTest.testFindById(CreditCardDAOTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)