When I try to cache a Criteria Query that is using a ResultTransformer, it causes an ClassCastException.
Sample Code:
Criteria criteria = session.createCriteria(User.class);
criteria.setProjection(Projections.projectionList().add(Projections.property("firstName")).add(Projections.property("lastName")));
criteria.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
criteria.setCacheable(true);
criteria.list();
Exception:
java.lang.ClassCastException: java.util.HashMap cannot be cast to [Ljava.lang.Object;
at org.hibernate.cache.StandardQueryCache.put(StandardQueryCache.java:104)
at org.hibernate.loader.Loader.putResultInQueryCache(Loader.java:2274)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2206)
at org.hibernate.loader.Loader.list(Loader.java:2164)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1706)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
I did some research into the problem and found this bug report:
http://opensource.atlassian.com/project ... e/HHH-2463. The last comment says that it should be fixed, but I am still seeing the bug in Hibernate 3.5. Does anyone know what the status of this bug is, or know what I can do to fix it? I know transforming the results after calling criteria.list() will avoid the exception, but I would rather not do that unless I have to.