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?