Repeatable-Reads for insert/update in database transactions in EAP
Issue
-
We have an application which exposes an
insertOrUpdatemethod via SOAP interface.
This method checks first if the ID passed as parameter (not the same ID of my DB), exists in DB with a method named 'alreadyInserted' and so decides to proceed with an insertion or an update (the business logic is pretty different between these methods). -
We noticed that this approach works well for most of the situations, but, when my webservice is called by an high concurrency platform, non-repeatable reads happens.
For example: two calls are made on my webservice passing the same ID with few milliseconds difference and they start two different transaction named T1 and T2.
T1 calls alreadyInserted, which returns false and so T1 proceeds with the insertion, but before T1 reaches the commit T2 also performs a call to 'alreadyInserted' method which still return false, because the record has not been persisted yet by T1.
So both of T1 and T2 performs an insertion, resulting on some record duplicated.
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.2.0
- MySQL DB
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
