-->
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.  [ 2 posts ] 
Author Message
 Post subject: Multi thread, duplicate inserts
PostPosted: Wed Feb 02, 2011 8:01 am 
Newbie

Joined: Thu Mar 05, 2009 1:54 pm
Posts: 4
Location: MK
Hi all,

I have an environment where multiple threads insert "message" objects.
Each message object has 1 related parent record, which just before the insert I query for that parent record and if found in the database, then I assign that object into the message object.

I have cascade="save-update" set. So if my related records do not exist they will get created by hibernate witchcraft.

Firstly let me say, I only have 1 parent record, all message objects reference this 1 record.
The problem I am seeing;
From a fresh database (completely clean of data), I run my app, 10 threads attempt to insert a different message.
Each thread, checks to see if the parent record exists, which it wont the first time.
So, cascading commit on the message creates this parent record. Only it creates the parent multiple times.

Which if my understanding is correct, makes sense.
For each thread, checkin the existence of the parent record, will show there is no parent record, so each will attempt to create it through the cascade.

Has anyone come across this sort of thing before and have any sggestions?

Thanks for reading.

_________________
www.holdemharrier.com


Top
 Profile  
 
 Post subject: Re: Multi thread, duplicate inserts
PostPosted: Wed Feb 02, 2011 10:59 am 
Newbie

Joined: Thu Mar 05, 2009 1:54 pm
Posts: 4
Location: MK
The only thing I can think to do is to create a unique composite index, so any duplicates through a Constraint violation.
Then catch this in code and not worry about it.

_________________
www.holdemharrier.com


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