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
|