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: stale data issues
PostPosted: Sun Mar 15, 2009 6:03 pm 
Newbie

Joined: Sun Mar 15, 2009 5:50 pm
Posts: 2
I'm experiencing "stale data" problems with my application, where there are two instances running at the same time. One instance updates a table, the other instance queries the table but gets the old data.

I've tried clear()ing the session, flush()ing the session, using the configuration option hibernate.cache.use_query_cache=false, having the session closed after even small operations (which, I know, is a silly level of granularity in most cases, I just wanted to see if that would help it refresh). I'm not sure what other options are available to me, this is sort of where I've run aground.

Hibernate version is 3.2.6. Database is MySql 14.12 distrib 5.0.51a, using the mysql-connector 5.0.8.


Top
 Profile  
 
 Post subject: more info
PostPosted: Sat Mar 28, 2009 5:06 pm 
Newbie

Joined: Sun Mar 15, 2009 5:50 pm
Posts: 2
I moved forward with setting hibernate.cache.use_second_level_cache to false, and after it still seemed to be grabbing from cache, changing straight to StatelessSession.

After it still got "old data" I went deeper into the rabbit hole and tried changing the isolation level from 4 (TRANSACTION_REPEATABLE_READ) to 1 (TRANSACTION_READ_UNCOMMITTED) , and immediately started getting the new data.

This implies I'm not committing my transaction -- but I am. I commit it and I get the following from the log :

14:51:35,425 DEBUG org.hibernate.transaction.JDBCTransaction:103 - commit
14:51:35,425 DEBUG org.hibernate.jdbc.JDBCContext:205 - before transaction completion
14:51:35,426 DEBUG org.hibernate.transaction.JDBCTransaction:116 - committed JDBC Connection
14:51:35,426 DEBUG org.hibernate.jdbc.JDBCContext:219 - after transaction completion
14:51:35,426 DEBUG org.hibernate.jdbc.ConnectionManager:404 - aggressively releasing JDBC connection
14:51:35,426 DEBUG org.hibernate.jdbc.ConnectionManager:441 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
14:51:35,427 DEBUG org.hibernate.connection.DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1


So I guess my question has changed to .. why would hibernate think it's successfully committed a transaction and the jdbc connection itself doesn't? Or alternately, if both sides are accepting that the transaction is properly committed, why would a TRANSACTION_REPEATABLE_READ setting get stale data but TRANSACTION_READ_UNCOMMITTED gets the right data?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 30, 2009 1:50 pm 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
Hi,
I have never changed the transaction isolation levels myself, but I did ran into the StaleObjectException during concurrency.
Have you tried something like this:-
Code:
myDAOmethod1() throws Exception(){
//some stuff
}

mymanager method1(){

try{
//call myDAOmethod1();
catch(Specific hibernate exception like stale object exception){
get a new Hibernate session. Eviction of the object does not help.
Session s = //somehow discard the session that is bound to this thread and get a new ones.
and call the myDAOmethod1();
}

Not sure if this is the right way to do or not but this helped in the past. In our application we sometimes do as above but most of the times we throw the same error to the user saying something like:- "Concurrency issue retry again."

Hope this helps,
Latha.


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.