-->
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.  [ 3 posts ] 
Author Message
 Post subject: JPA 2.0 EnumType ClassCastException java.util.LinkedList
PostPosted: Sat Oct 30, 2010 1:49 pm 
Newbie

Joined: Sun Feb 08, 2009 10:05 pm
Posts: 11
Hi all,

I've been fighting this weird issue with JPA 2.0 + Hibernate 3.5.0 + MySQL with Enums. Here is my query:

@NamedQuery(name = "getEventsByDistanceAndEventTypes", query = "SELECT new Event(events.eventId, events.name, events.location, events.startDate, events.endDate, events.resort.location, " + "glength(events.resort.location, :location), events.type, events.contact, events.costs, events.description, events.email, " + "events.url) FROM Event events LEFT JOIN events.resort WHERE contains(:bounds, events.resort.location) = true AND (events.type IN (:types)) ORDER BY 7, events.startDate")

When I run this @NamedQuery, I am passing a Collection<MyEnumType> as the value of the types parameter through the EntityManager API, but I am getting a ClassCastException...Hibernate is trying to cast the types to an Enum rather than realizing that I am sending a Collection of Enums.

Has anyone ever tried this before?

Here is the exception:

11:11:00,623 WARN EventsController:123 - java.util.ArrayList cannot be cast to java.lang.Enum
java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Enum
at org.hibernate.type.EnumType.nullSafeSet(EnumType.java:148)
at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:183)
at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:67)
at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:567)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1612)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
at org.hibernate.loader.Loader.doList(Loader.java:2294)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
at org.hibernate.loader.Loader.list(Loader.java:2167)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:448)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)


Top
 Profile  
 
 Post subject: Re: JPA 2.0 EnumType ClassCastException java.util.LinkedList
PostPosted: Sat Oct 30, 2010 2:36 pm 
Newbie

Joined: Sun Feb 08, 2009 10:05 pm
Posts: 11
To Clarify, this works just fine if I use the javax.persistence.Query interface but fails when I drop down to org.hibernate.Query. Would it be possible to simulate the transformations that JPA does...but Hibernate fails to do?


Top
 Profile  
 
 Post subject: Re: JPA 2.0 EnumType ClassCastException java.util.LinkedList
PostPosted: Sat Oct 30, 2010 2:42 pm 
Newbie

Joined: Sun Feb 08, 2009 10:05 pm
Posts: 11
I figured out I have to call org.hibernate.Query.setParameterList()

Thanks


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

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.