-->
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.  [ 5 posts ] 
Author Message
 Post subject: SaveorUpdate syncronisation
PostPosted: Sun Oct 26, 2008 6:00 pm 
Newbie

Joined: Sun Oct 26, 2008 5:49 pm
Posts: 6
Hello ,

i am currently working with hibernate3.3

in our code we load the session obj from the config (no spring support) ... and keep this in the ThreadLocal.

Our app is a multiThreaded application . On a request we create a new thread and call saveorupdate by getting the session from the threadlocal ....

i am currently getting a DUPLICATE_KEY exception when i call this method simultaneously from 2 thread .... i have flushed the session and also made a commit, but looks like before i flush the 2nd thread fires the update and i get into this issue.

Any thoughts on this will is highly appreciated.

regards
Praveen


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 26, 2008 6:53 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Hibernate basically doesn't have a way to handle this (aside from versions and optimistic locking), it piggybacks on the transaction management system your database has.
Either manipulate your locking parameters, or add thread sychronization code on your application.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2008 11:33 am 
Newbie

Joined: Sun Oct 26, 2008 5:49 pm
Posts: 6
Thanks Gonzo,


i have added a locking on my session object since i suspected the same session object was getting used for the two transactions, but seems like thats not the case and the issue wasnt resolved,

As far as i think i will need to syncronize on the object itself now.. but that will be a bigger penality on performance and i dont want to go in that direction.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2008 1:52 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
My name is Gonzalo.

If you don't want to add synchronization code, then you will have to tune your DB to accept concurrent updates. Hibernate sessions don't handle concurrent access.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject: SaveorUpdate
PostPosted: Tue Oct 28, 2008 8:48 pm 
Newbie

Joined: Sun Oct 26, 2008 5:49 pm
Posts: 6
Sorry.. for the name thing..

well.. i think i need to do some more RnD on to how can update fire an insert .. when i have the data in the DB .... thats whats bugging me.


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