ayadav wrote:
Here is the code snippet.
Transaction transaction = null;
session.setFlushMode(FlushMode.NEVER);
transaction = this.session.beginTransaction();
transaction.begin();
session.saveOrUpdate(object);
this.session.flush();
if (transaction != null) {
transaction.commit();
}
session.evict(object)
closeSession();
open anther session.
session.list(query);
The list return a different result then what is in the database. The update is fine.
I am using EhCache. I tried various options like turning off query cache, second level cache etc. But no use. Also, like I said this problem happened when I upgraded to 3.2.5. Everthing was fine prior to that.
Thanks
Something doesn't look right here. This is not a cache issue if you get the same results when you turn off caches. These are the things that come to my mind:
1- You are creating a new transaction which might be nested into an existing transaction and evicting the object before the outer transaction commits will discard the change (I am not very sure here but studying the code makes this clear).
2- Use a JDBC logger (p6spy) and see if your entity makes it to database.
3- Query cache checks update time stamp cache to see if it needs to throw away a currently cached query result. Make sure update stamp cache stays long enough for the second session.
4- Why don't you try this code as suggested in documentation?
Code:
Session sess = factory.openSession();
Transaction tx;
try {
tx = sess.beginTransaction();
//do some work
...
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
sess.close();
}