-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JPA: CollectionOfElements with EnumType.ORDINAL?
PostPosted: Fri Feb 04, 2011 3:16 pm 
Newbie

Joined: Fri Feb 04, 2011 3:07 pm
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.