Dear hibernate professionals,
We are experiencing a problem when trying to activate caching on our hibernate query.
The Problem is within how the QueryKeys are collected.
We are using Hibernate 4.0.1.Final (stuck to that due to https://hibernate.atlassian.net/i#browse/HHH-7391 and XML-Mappings)
and also using EHCache for caching purposes.
I have configured an EHCache for each query to be cached (own region) and I am trying to cache a query as follows (simplyfied for several reasons):
Note: The CachingRegion has been set correctly, I am NOT caching the hibernate entities in the same cache as the queries.
Code:
select distinct a from MyClass a where MyClass.key in (:keys)
Whereas "keys" is set as a list parameter and each is of class "Key".
The key class looks as followed (simplified, contains several logic):
Code:
public class Key {
private String rawKey;
public String getRawKey() { return rawKey; }
public void setRawKey(String value) { rawKey = value; }
}
The interesting part of the mapping of "MyClass" is
Code:
<component name="key" class="mypackage.Key" update="false">
<property name="rawKey" type="java.lang.String" access="property" column="rawKey" not-null="false" unique="true" />
</component>
Now back to the real problem:
When I set Cacheable to be "true" on the query hibernate tries to generate a QueryKey for the query.
I tracked down the problem to be issued by QueryKey#generateQueryKey (starting in line 79).
Since I provided namedParameters (I tried it with positional ones as well), I will only give an explanation for the named ones.
In line 106 the named parameter gets disassembled down to its components:
Code:
namedParameterEntry.getValue().getType().disassemble(
namedParameterEntry.getValue().getValue(),
session,
null
)
Then all this is wrapped in a TypedValue. Problem here is that calling hashCode() on the TypedValue will cause it to invoke a getter
for the original class on the disassembled object (which is an object array of one string (raw property).
This will result in a ClassCastException.
I do not know, if we missed something with the mapping or this is just a bug, so I'd be very thankful for any hints/solutions for this
problem.
Best regards,
Christian