-->
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.  [ 7 posts ] 
Author Message
 Post subject: Updates not flushed when mixing Session.saveOrUpdate and HQL
PostPosted: Wed Jun 29, 2016 8:03 am 
Newbie

Joined: Tue May 19, 2015 7:52 am
Posts: 5
Hi all,

I'm trying to debug a stale state problem in a fairly large application running in JBoss. The problem is that entities saved with saveOrUpdate will not get flushed and my HQL queries will fail because of the stale state.

As the application logic is rather large, I'm attaching a pseudoish code to illustrate the problem.
Code:
Session s = HibernateUtil.getCurrentSession //current JTA bound session
s.setFlushMode(FlushMode.ALWAYS);

myEntity.setA(1)
s.saveOrUpdate(myEntity);

s.createQuery("FROM MyEntity WHERE a = 1").uniqueResult() //returns null
s.flush()
s.createQuery("FROM MyEntity WHERE a = 1").uniqueResult() //returns the correct object


Why is the first HQL query failing to see the changes in MyEntity?

I have understood that the changes should be flushed by Hibernate before the first HQL query hits DB. Is this assumption incorrect? Is there something fundamentally wrong with this code snippet?


Top
 Profile  
 
 Post subject: Re: Updates not flushed when mixing Session.saveOrUpdate and HQL
PostPosted: Wed Jun 29, 2016 8:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
What Hibernate version are we talking about?


Top
 Profile  
 
 Post subject: Re: Updates not flushed when mixing Session.saveOrUpdate and HQL
PostPosted: Wed Jun 29, 2016 8:37 am 
Newbie

Joined: Tue May 19, 2015 7:52 am
Posts: 5
mihalcea_vlad wrote:
What Hibernate version are we talking about?


4.3.6


Top
 Profile  
 
 Post subject: Re: Updates not flushed when mixing Session.saveOrUpdate and HQL
PostPosted: Wed Jun 29, 2016 9:17 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
That's strange because last time I checked it, it worked just fine.

You can try with 4.3.11.Final and see if it works better. Or try with a new release. Hibernate 4.x is not supported by the Hibernate dev team, so, if it's a bug, you'll have to fix it yourself and then it might get integrated into a new release.

If the bug replicates in Hibernate 5.2 and you provide a replicating test case, we can fix it, but you'll have to migrate to the latest version.


Top
 Profile  
 
 Post subject: Re: Updates not flushed when mixing Session.saveOrUpdate and HQL
PostPosted: Wed Jun 29, 2016 10:03 am 
Newbie

Joined: Tue May 19, 2015 7:52 am
Posts: 5
mihalcea_vlad wrote:
That's strange because last time I checked it, it worked just fine.

You can try with 4.3.11.Final and see if it works better. Or try with a new release. Hibernate 4.x is not supported by the Hibernate dev team, so, if it's a bug, you'll have to fix it yourself and then it might get integrated into a new release.

If the bug replicates in Hibernate 5.2 and you provide a replicating test case, we can fix it, but you'll have to migrate to the latest version.


I tried with 4.3.11 and the problem still existed. The problem might also be caused by some unorthodox configurations of the legacy application I'm working on. Thus I mainly wanted to make sure that I had understood correctly how things should work.

Currently I am not able to upgrade to Hibernate 5, so for now I have to settle for manually flushing the session whenever I run into problems.

Thank you for the help!


Top
 Profile  
 
 Post subject: Re: Updates not flushed when mixing Session.saveOrUpdate and HQL
PostPosted: Wed Jun 29, 2016 10:30 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
This is quite a serious issue that might get fixed if you can replicate it. You can use out templates for that. If you can't replicate it, then it's a config issue as you suggested already.


Top
 Profile  
 
 Post subject: Re: Updates not flushed when mixing Session.saveOrUpdate and HQL
PostPosted: Fri Jul 01, 2016 4:37 am 
Newbie

Joined: Tue May 19, 2015 7:52 am
Posts: 5
Apparently the problem was indeed in the configuration of my application.

The application is running inside JBoss and using EJB with CMT. hibernate.transaction.factory_class was set to org.hibernate.transaction.JTATransactionFactory while it should have been org.hibernate.transaction.CMTTransactionFactory. With JTATransactionFactory everything else works, but the intermediate flushing fails. With CMTTransactionFactory everything works as they should.


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