-->
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: Multi Threading problem (Complex issue)
PostPosted: Mon Dec 04, 2006 5:34 pm 
Beginner
Beginner

Joined: Thu Nov 02, 2006 2:23 pm
Posts: 33
Hey,

Lets say i have a Buyer obj , each Buyer has reference to BooksCollection obj .The primary key of BooksCollection is the hash value of the names of the books that it contains.

In the BuyerDAO i check (by session.get ) if the BooksCollection already in the seesion.

In case it is i get it from the session and set it to the Buyer

Than call to session.saveOrUpdate(Buyer)

Scenario:
Multi thread application.
Two Buyer with the same BooksCollection from differents threads come in the same time.

Code:
Exception - java.sql.SQLException: Duplicate entry '1075191317' for key 1


I close the session and try to save (The same logic like above) the Buyer again , but faild with :
Code:
org.hibernate.StaleStateException: Unexpected row count: 0 expected: 1


Please, Please ,Please,
I am trying to sove it for a long time.

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 04, 2006 9:14 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
session impls are not thread safe

It is not intended that implementors be threadsafe. Instead each thread/transaction
* should obtain its own instance from a <tt>SessionFactory

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject: It is a diffrent session instance for each thread.
PostPosted: Tue Dec 05, 2006 2:15 am 
Beginner
Beginner

Joined: Thu Nov 02, 2006 2:23 pm
Posts: 33
I think that the problem in the first try is that the same BookCollection arrive at the same time (this is a webservice , so different threds, different session), so when they check if BookCollection is already exists they get false and they both trying to save it at the same time, so only one success (duplicate). i dont know how to solve it.

In the second try the BookCollection is already exists, it get it from the session and do saveOrUpadte to buyer , but failed because StaleStateException , i have no idea why, and how to debug it.

Thank you


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.