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)
|