-->
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.  [ 4 posts ] 
Author Message
 Post subject: Externally updated column value not getting refreshed
PostPosted: Thu Mar 05, 2009 8:27 pm 
Newbie

Joined: Mon Jun 05, 2006 10:30 am
Posts: 7
I have a use case where a column (not key) value may get updated by another application and i want hibernate to see the change. Unfortunately every time i execute the query i always get the old column value.

I'm opening and closing a session every time so it can't be the session cache. I've turned off query and second level cache. I've called session.refresh on the return object. Nothing worked and i'm running out of ideas.

Any ideas would be great.
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 8:43 pm 
Newbie

Joined: Mon Jun 05, 2006 10:30 am
Posts: 7
I've found a workaround on this thread where if i do the following just after the query execution the value is refreshed:

Code:
Transaction t = session.beginTransaction();
t.commit();
session.refresh(myValue);


So doing a refresh doesn't work but starting a dummy transaction just before doing the refresh works ???
Is there any explanation for this and a more elegant way to solve the problem ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 06, 2009 3:33 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Which transaction isolation level are you using? From your description it seems like it could be TRANSACTION_REPEATABLE_READ, which means that once you have started your transaction, you will no longer see updates that are made in other transactions. This may be why starting a dummy transaction works as a workaround, since that sets a new starting point for the "repeatable" reads.

You may try setting the 'hibernate.connection.isolation' configuration value. See http://www.hibernate.org/hib_docs/v3/re ... ional.html for more information. I think TRANSACTION_REPEATABLE_READ=4 and TRANSACTION_READ_COMMITTED=2


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 06, 2009 12:35 pm 
Newbie

Joined: Mon Jun 05, 2006 10:30 am
Posts: 7
nordborg wrote:
Which transaction isolation level are you using? From your description it seems like it could be TRANSACTION_REPEATABLE_READ, which means that once you have started your transaction, you will no longer see updates that are made in other transactions. This may be why starting a dummy transaction works as a workaround, since that sets a new starting point for the "repeatable" reads.

You may try setting the 'hibernate.connection.isolation' configuration value. See http://www.hibernate.org/hib_docs/v3/re ... ional.html for more information. I think TRANSACTION_REPEATABLE_READ=4 and TRANSACTION_READ_COMMITTED=2


Setting hibernate.connection.isolation to 2 worked great.
Many thanks.


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