-->
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: concurrency issue
PostPosted: Tue Jul 14, 2009 12:00 pm 
Newbie

Joined: Tue Jul 14, 2009 11:42 am
Posts: 2
Hi.

I have several working threads. Every thread can add data to datebase. It is possible situation when the same bussines entity will be added to datebase by two threads in the same time. So after that I have two copies of the one entity with different identificators.

Can NHibernate help to deal with that? Is it my job?


Top
 Profile  
 
 Post subject: Re: concurrency issue
PostPosted: Wed Jul 15, 2009 6:49 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Yes, hibernate can help you there:

http://nhforge.org/doc/nh/en/index.html#transactions

In short words, you can add versioning columns to your entities and hibernate will handle this for you. You then get exceptions when you try to save modifications and don't have the newest version. Addionally there is a "select-before-update" flag, you can add to the class mapping.

But that only solves the issues when you try to modify entries. If you want consistent objects in all threads you have to think about using hibernate caching:

http://nhforge.org/doc/nh/en/index.html#performance-cache

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: concurrency issue
PostPosted: Thu Jul 16, 2009 7:02 am 
Newbie

Joined: Tue Jul 14, 2009 11:42 am
Posts: 2
In my case the same business entity does not mean the same business class. Threads do not share entity pool. Every thread creates entities. So if two threads create the same entity at the same time... I guess second level cache is useless in such situation. Maybe I got something wrong.


Top
 Profile  
 
 Post subject: Re: concurrency issue
PostPosted: Thu Jul 16, 2009 7:37 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Afaik the cache operates or can operate across threads. So each of you thread would check the cache first and then if necessary load the object. But I'm not sure about that.

_________________
--Wolfgang


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.