-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate 4.0.1.Final
PostPosted: Wed Oct 16, 2013 8:18 am 
Newbie

Joined: Wed Oct 16, 2013 7:37 am
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: Hibernate 4.0.1.Final
PostPosted: Thu Oct 17, 2013 7:14 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
thanks for the careful explanation. Looks like something could be wrong with the equals or hashcode implementation of your Key implementation? Could you post it, and also post the stacktrace?

Quote:
We are using Hibernate 4.0.1.Final (stuck to that due to https://hibernate.atlassian.net/i#browse/HHH-7391 and XML-Mappings)

Being stuck on 4.0.1 is probably the more concerning issue you're facing. Why is HHH-7391 holding you back?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Hibernate 4.0.1.Final
PostPosted: Sun Nov 10, 2013 4:08 pm 
Newbie

Joined: Wed Oct 16, 2013 7:37 am
Posts: 2
Hi again and thank you for your answer.
Well, it seems like that class cast exception occurs before even using hashCode or equals.
It happens while trying to generate the QueryKey and accessing the property required.
That hibernate issue described is holding us back since we can't activate the NaturalId driven 2nd Level Cache via XML-Mappings.
The architect does not want to use annotation driven mappings (call it a personal flavor).

We disabled query caching for now.
Christian


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.