-->
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 intermittently returned within web application
PostPosted: Thu May 28, 2009 5:38 pm 
Beginner
Beginner

Joined: Fri Oct 27, 2006 3:35 pm
Posts: 21
Hi Folks,

I know this has come up a few times before - I've looked at some of the other threads on this issue but nothing has seemed to help much.

I'm developing an "online shop" web application and I've run into a curious issue in which I occasionally get an out-of-date version of model data from Hibernate. I'm using the open session in view pattern, opening the session when an http request hits my control servlet and closing it again with a filter once my view has finished rendering. This seems to occur when I'm adding an item to the basket - I'll add an item (the hibernate session opens, associations between product, basket item, basket etc are updated before the hibernate session is finally closed). Often when the page reloads (new hibernate session opens, stuff is pulled out of the model, view is rendered, session is closed) I won't see my item in the basket! If I hit refresh in the browser, it usually appears. Sometimes it takes a couple of refreshes...

I know it's not a browser caching issue, as if I put a break point in my code I can see the "stale" data coming back through the Hibernate session. I've experimented with changing the transaction isolation level, but it doesn't seem to have much of an impact (unless I use 'serializable', but that's really not a realistic option).

I've tried other clutching-at-straws stuff such as disabling the query cache, and the second level cache, and also explicitely 'evicting' the hibernate managed objects that I'm updating from the session cache, but again none of this has really had a notceable impact.

If anyone has any ideas, or anything else to try I'm all ears!

Many thanks,
Richard.

I'm using Hibernate 3.3.1, MySQL 5.x, Tomcat 5.5.27 & J6SE


Top
 Profile  
 
 Post subject: Re: Stale data intermittently returned within web application
PostPosted: Fri May 29, 2009 1:04 pm 
Beginner
Beginner

Joined: Fri Oct 27, 2006 3:35 pm
Posts: 21
Just to follow up, I've been investigating this some more today. I've created a little if (...) block that is only entered when hibernate's view of the db and the actual db content are found to be out of synch. It's interesting - an object that I know was persisted during a previous hibernate session can no longer be found through hibernate. Even if I do session.createSQLQuery and try to retrieve the object by id it can't be found. Yet, if I open up the table in SQLYog, I can see that the row IS there.

I've got my transaction isolation level set to repeatable read, as it seems to behave slightly better than read committed. I guess with repeatable read you'd expect the same data to come back every time you execute the same query using a given database connection... I just don't understand why this happens intermittently.

Could this be a MySQL driver issue? Or a C3P0 issue? I think I will try updating these next.

Cheers.


Top
 Profile  
 
 Post subject: Re: Stale data intermittently returned within web application
PostPosted: Fri May 29, 2009 2:47 pm 
Beginner
Beginner

Joined: Fri Oct 27, 2006 3:35 pm
Posts: 21
Aha!

If I deploy the application (i.e. in Tomcat, without Eclipse/Sysdeo), the issue is resolved!

Why on earth would that be? Anyone encountered problems like this?


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.