Hi all, 

We have encountered a scenario, which we have not yet found a good way to 
handle. The scenario seems common enough, to expect that others may already 
have dealt with it.

*Scenario*
We have a message type (MyMessage) which results in an entity (Entity1) 
being inserted into a database. Entity1 references another entity (Entity2) 
which is identified in MyMessage by an id. If Entity2 already exists Entity1 
will reference the existing, if not Entity2 will be inserted in the same 
unit of work as Entity1. The unit of work is implemented in a message 
module.

Our service bus instance processes messages using several threads. If two 
instances of MyMessage is processed simultanously and both reference the 
same Entity2, two instances of Entity2 will be inserted in the database 
instead of one.

Does anyone have a nice solution to this problem? 
Currently we are saving Entity2 in the MyMessage consumer (flushing our 
NHibernate session) and surrounding the saving of Entity2 with a lock...

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino Tools Dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rhino-tools-dev/-/mSW-XMMH8tcJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rhino-tools-dev?hl=en.

Reply via email to