OK, I Googled all over for this and found literally nothing. So here goes...
I'm using Hibernate 3.4 implementation of the JPA.
Q: Is it possible to map a collection of Java 5 enum instances using EnumType.ORDINAL?
I have a class with the following mapping (PaymentMethod is a java enum):
Code:
@CollectionOfElements
@JoinTable(name="ListingPreferencesPaymentMethods", joinColumns=@JoinColumn(name="listingPreferencesEntityId", referencedColumnName="entityId"))
@Column(name="paymentMethod")
@Enumerated(EnumType.ORDINAL)
private Set<PaymentMethod> paymentMethods;
When trying to access this in a test:
Code:
prefs.getPaymentMethods().size();
This blows up. It appears as if the @Enumerated annotation isn't used in this context. Is this true?
Here's the exception:
Quote:
java.lang.IllegalArgumentException: Unknown name value for enum class com.tuffwerx.domain.model.PaymentMethod: 4
at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:113)
at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:128)
at org.hibernate.persister.collection.AbstractCollectionPersister.readElement(AbstractCollectionPersister.java:725)
at org.hibernate.collection.PersistentSet.readFrom(PersistentSet.java:341)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:1031)
at org.hibernate.loader.Loader.readCollectionElements(Loader.java:669)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:614)
at org.hibernate.loader.Loader.doQuery(Loader.java:724)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2015)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:59)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:587)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1743)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:366)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:131)
at org.hibernate.collection.PersistentSet.size(PersistentSet.java:162)
Thanks for your help.