Caching queries like "select cat.eyes from Cat cat where cat.id=?" where cat.eyes is a Bag does not work - cache returns a list with one element in it - null.
Reasons: StandardQueryCache contains following code:
Code:
for ( int i = 0; i < result.size(); i++ ) {
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
)
);
}
}
Where returnTypes is [org.hibernate.type.BagType] and BagType.disassemble
requires owner argument which is passed as null - see last arg at
Code:
returnTypes[0].disassemble( result.get( i ), session, null )
In other words, if we are caching Bag, BagType.disassemble is called with owner=null and current implementation returns null if there is no owner.
Is this behaviour intentional? Or will it be fixed? How can i cache bags?