I have an event-driven application based on MDB, spring integration and JPA for persistence. The application is deployed on weblogic 10.3 with a max-pool-size default value (16).
My application need to handle some messages that modfies DB. Imagine that I have use case where I have to handle some messages that for their logic need to insert a domain object if it does not exist or update it if it exists.
So my component that modifes the DB check if the object exists or not and then call the merge on JPA. Since two concurrent messages are executed in parallel when I call the merge on dao, JPA triggers two insert statement since the object is not yet persisted and so only one of them is correctly executed.
Is there a pattern to handle this kind of "race condition" in an event-driven application?
Kind regards Massimo