[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2463?page=c...
]
Abhishek Mirge commented on HHH-2463:
-------------------------------------
The hibernate currently is not able to cache criteria query while using result transformer
solution for this can be implemented in following way. First dont use the current
hibernate ResultTransformer , directly call criteria.list()
The what ever result is cominng just pass to the method public static List
transformToBean(Class resultClass, String aliasList[], List resultList) of my custom
ResultTransformer .
I have uploaded one custom ResultTransformer for criteria query using this transformer one
can use the cache avoid the exception which is coming when caching criteria query.
Hibernate Developer: This bug can be resolved if we cache first and then use
ResultTransformer.
ClassCastException when Hibernate tries to cache results using
ResultTransformer
--------------------------------------------------------------------------------
Key: HHH-2463
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2463
Project: Hibernate3
Issue Type: Bug
Affects Versions: 3.2.2
Reporter: Peak user
Attachments: ResultTransformerUtil.java
When Hibernate executes a cacheable query using a ResultTransformer, it will attempt to
cache the results AFTER applying the ResultTransformer. The problem is that the
ResultTransformer may modify the data in a way that Hibernate won't understand it
anymore, and in this case it will generate a ClassCastException when trying to cache it.
This problem could be easily solved if Hibernate cached results before applying the
ResultTransformer instead of afterwards.
Here's a sample code to reproduce this problem:
class ToMapResultTransformer implements ResultTransformer {
private String[] properties;
public ToMapResultTransformer(String[] properties) {
this.properties = properties;
}
public List transformList(List collection) {
return collection;
}
public Object transformTuple(Object[] tuple, String[] aliases) {
Map<String,Object> result = new
HashMap<String,Object>(tuple.length);
for (int i=0; i<tuple.length; i++) {
result.put((properties != null ? properties[i] : aliases[i]), tuple[i]);
}
return result;
}
}
Criteria sqlCriteria = createSqlCriteria(session);
sqlCriteria.setProjection(projections);
sqlCriteria.setCacheable(true);
sqlCriteria.setResultTransformer(new ToMapResultTransformer(properties));
sqlCriteria.list();
The code above produces the following exception:
java.lang.ClassCastException: java.util.HashMap
at org.hibernate.cache.StandardQueryCache.put(StandardQueryCache.java:83)
at org.hibernate.loader.Loader.putResultInQueryCache(Loader.java:2185)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2087)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira