[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2525?page=c...
]
Jeremy Grodberg commented on HHH-2525:
--------------------------------------
It looks to me like this problem starts manifesting in StandardQueryCachce.put() lines
78-84 (in both Hibernate core 3.2.4sp1 and 3.2.6.ga:
if ( returnTypes.length==1 ) {
cacheable.add( returnTypes[0].disassemble( result.get(i), session, null ) );
}
else {
cacheable.add( TypeFactory.disassemble( (Object[]) result.get(i), returnTypes,
null, session, null ) );
}
In my case, my SQL query does eager fetching of an associated object, so even though the
returnType is length 1 (value is ManyToOneType), the result is actually an array of 2
objects, the primary object and the associated object.
I don't know if that's a bug in StandardQueryCache.put() or a bug in
ManyToOneType.disassemble() that they don't properly handle results/objects that are
arrays or if the bug is in CustomLoader or Loader in that the resultType passed to
listUsingQueryType is the resultType of the post-transformer result but the list being put
into the cache is the pre-transformer list. I suspect the latter.
Bug when using a ResultTransformer on a cached query
----------------------------------------------------
Key: HHH-2525
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2525
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.2
Environment: Firebird 2.0 on Win XP
Reporter: Sebastien Cesbron
Attachments: testhib.zip
Using a distinct result transformer which a cached like this :
query = session.createQuery("select obj from ObjetTest obj left outer join fetch
obj.children as obj_0 order by obj.id asc");
query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
query.setCacheable(true);
query.list();
This leads to this exception
2007-03-21 14:28:20,589 ERROR : IllegalArgumentException in class: ObjetTest, getter
method of property: oid
Exception in thread "main" org.hibernate.PropertyAccessException:
IllegalArgumentException occurred calling getter of ObjetTest.oid
at
org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at
org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:183)
at
org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3524)
at
org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3240)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
at
org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:218)
at org.hibernate.type.ManyToOneType.disassemble(ManyToOneType.java:163)
at org.hibernate.cache.StandardQueryCache.put(StandardQueryCache.java:80)
at org.hibernate.loader.Loader.putResultInQueryCache(Loader.java:2118)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2062)
at org.hibernate.loader.Loader.list(Loader.java:2020)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at Test.main(Test.java:33)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring
class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
... 16 more
It seems this is due to a difference in QueryLoader.getResultColumnOrRow. In this method
there is a test :
else if ( !hasTransform ) {
return row.length == 1 ? row[0] : row;
}
This causes the method to return an instance of ObjetTest in one case and an instance of
ObjetTest[1] in the other one. In the latter test, when putting the query into the query
cache, hibernate calls the getOid method on an array of ObjetTest and this causes the
exception
--
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