-->
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.  [ 7 posts ] 
Author Message
 Post subject: Old data is read after Transaction.comit()
PostPosted: Fri Jun 03, 2005 4:51 am 
Newbie

Joined: Fri Jun 03, 2005 4:42 am
Posts: 4
After the code
Code:
    Session hs = getSession();
    Transaction tx = hs.beginTransaction();
    hs.saveOrUpdate(bean);
    tx.commit();

a new thread is started and sometimes reads old value of bean.

How can I be sure that data in database is already updated?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 9:29 am 
Beginner
Beginner

Joined: Wed Feb 11, 2004 6:08 am
Posts: 29
Location: Germany
try session.flush() to synchronize session cache with db or session.evict(bean) to remove bean from session cache (and force reload).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 9:41 am 
Newbie

Joined: Fri Jun 03, 2005 4:42 am
Posts: 4
dirkschmidt wrote:
try session.flush() to synchronize session cache with db or session.evict(bean) to remove bean from session cache (and force reload).

Session has COMMIT flushMode and bean changes are successfully transfered into database. The problem in second thread that was started after commit and has already read old value of bean before the database updating.
The question is "How to stop execution until the data will be transfered into database?"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 9:47 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi

Try using a LOCK

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 10:13 am 
Newbie

Joined: Fri Jun 03, 2005 4:42 am
Posts: 4
ramnath wrote:
Try using a LOCK

Can you give some example? We can't lock object along with reading.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 10:32 am 
Newbie

Joined: Tue Mar 22, 2005 5:43 pm
Posts: 16
Location: Teksouth
Have you tried

Session.refresh(object).

This refreshes the saved object with new values so you don't have to read it again.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 10:43 am 
Newbie

Joined: Fri Jun 03, 2005 4:42 am
Posts: 4
lqycfnd wrote:
Have you tried

Session.refresh(object).

This refreshes the saved object with new values so you don't have to read it again.

How should the second thread guess that it should call Session.refresh(object)? And when should it do that?


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