Java Mailing List Archive

http://www.gg3721.com/

Home » Hibernate Issues List »

[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-2463)
ClassCastException when
Hibernate tries to cache results using ResultTransformer

Anupam M (JIRA)

2008-08-04


Author LoginPost Reply

  [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2463?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Max Rydahl Andersen resolved HHH-2463.
--------------------------------------

  Resolution: Duplicate

should be fixed now by fix to related bug - open new issue if still an issue.

> 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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

   
_______________________________________________
hibernate-issues mailing list
hibernate-issues@(protected)
https://lists.jboss.org/mailman/listinfo/hibernate-issues
©2008 gg3721.com - Jax Systems, LLC, U.S.A.