-->
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.  [ 10 posts ] 
Author Message
 Post subject: Hibernate 4 upgrade - Query Cache issue with Spring
PostPosted: Fri Jan 27, 2017 12:04 pm 
Newbie

Joined: Fri Jan 27, 2017 11:48 am
Posts: 5
Hello hibernate users,

We’re currently upgrading our codebase from Hibernate 3 to Hibernate 4.3.7, and have run into an issue with the query cache during testing. Once a transaction has been committed, the cache is no longer being hit on subsequent queries. After some investigation we’ve found that it’s due to the UpdateTimestampsCache.invalidate method not being called when the transaction is committed. This leaves the UpdateTimestampsCache with the timestamps generated during the preinvalidate method, which includes the lock timeout duration (60s default), thus subsequent entries in the cache look out of date and aren’t used.

We are using SpringSessionContext, and it seems the implementation of SpringSessionSynchronization.afterCompletion has changed between hibernate 3 and 4 and no longer calls SessionImplementor.afterTransactionCompletion, which in turn lead to the UpdateTimestampsCache.invalidate being called. Has anyone encountered this issue already and know of a workaround?

Any assistance is much appreciated.


Top
 Profile  
 
 Post subject: Re: Hibernate 4 upgrade - query cache issue
PostPosted: Fri Jan 27, 2017 1:13 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Make sure that you use Spring 4, and not Spring 3. According to Spring docs:

Quote:
Note that Hibernate 4.3 is a JPA 2.1 provider and therefore only supported as of Spring Framework 4.0. The same applies to Hibernate Validator 5.0 as a Bean Validation 1.1 provider. Neither of the two are officially supported with Spring Framework 3.2.


Top
 Profile  
 
 Post subject: Re: Hibernate 4 upgrade - query cache issue
PostPosted: Fri Jan 27, 2017 1:17 pm 
Newbie

Joined: Fri Jan 27, 2017 11:48 am
Posts: 5
vlad wrote:
Make sure that you use Spring 4, and not Spring 3. According to Spring docs:

Quote:
Note that Hibernate 4.3 is a JPA 2.1 provider and therefore only supported as of Spring Framework 4.0. The same applies to Hibernate Validator 5.0 as a Bean Validation 1.1 provider. Neither of the two are officially supported with Spring Framework 3.2.


Hello, yes we are using Spring 4.2.6 and the hibernate4 library - org.springframework.orm.hibernate4.SpringSessionContext;


Top
 Profile  
 
 Post subject: Re: Hibernate 4 upgrade - Query Cache issue with Spring
PostPosted: Fri Jan 27, 2017 3:12 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
That's strange I summarized the Query Cache operations in this article.

Maybe you run into some bug. Unfortunately, Hibernate 4.x is not under development, so even if it's a bug, it will not be fixed. You'll have to test it against Hibernate 5.2, and if the bug replicates then we will fix it.


Top
 Profile  
 
 Post subject: Re: Hibernate 4 upgrade - Query Cache issue with Spring
PostPosted: Wed Feb 01, 2017 10:49 am 
Newbie

Joined: Fri Jan 27, 2017 11:48 am
Posts: 5
I've tested against Hibernate 5 and the issue still persists. Regardless of which version we're using, I'm confused as to how the query cache will work if the updateTimestampsCache is not invalidated after the transaction is committed. Any assistance is appreciated.


Top
 Profile  
 
 Post subject: Re: Hibernate 4 upgrade - Query Cache issue with Spring
PostPosted: Wed Feb 01, 2017 12:12 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
If you can come up with a replicating test case that demonstrates the issue, then you should open a bug for Hibernate 5.2.


Top
 Profile  
 
 Post subject: Re: Hibernate 4 upgrade - Query Cache issue with Spring
PostPosted: Fri Feb 03, 2017 10:04 am 
Newbie

Joined: Fri Jan 27, 2017 11:48 am
Posts: 5
I don't think it's a bug. What I see is that in SessionImplementor, the afterTransactionCompletion method is no longer present in version 4/5 as it was in 3. All we need to know is how we are supposed to perform the post transaction activities (such as invalidating the query cache) given that this method is deprecated.


Top
 Profile  
 
 Post subject: Re: Hibernate 4 upgrade - Query Cache issue with Spring
PostPosted: Mon Feb 06, 2017 4:14 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
The UpdateTimestampCache.invalidate method is called by the AfterTransactionCompletionProcessQueue callback of ActionQueue:

Code:
session.getFactory().getUpdateTimestampsCache().invalidate(
    querySpacesToInvalidate.toArray(
        new String[querySpacesToInvalidate.size()]
    ),
    session
);


This callback is triggered by the afterTransactionCompletion method of the SessionImpl object.


Top
 Profile  
 
 Post subject: Re: Hibernate 4 upgrade - Query Cache issue with Spring
PostPosted: Mon Feb 06, 2017 5:32 am 
Newbie

Joined: Fri Jan 27, 2017 11:48 am
Posts: 5
As I mentioned in my original post - the implementation of SpringSessionSynchronization.afterCompletion has changed between hibernate 3 and 4 and no longer calls SessionImpl.afterTransactionCompletion.

As this issue resides inside the spring-orm-4.2.6 jar, I presume this is a spring ORM issue rather than hibernate then?


Top
 Profile  
 
 Post subject: Re: Hibernate 4 upgrade - Query Cache issue with Spring
PostPosted: Mon Feb 06, 2017 5:45 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Yes. This is a Spring issue, and you should report it on their forum. Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.