'Hibernate Executes the failed insert query multiple times after catching the exception
I tried to insert a record into the database and the action failed with "UniqueConstraint Validation". I handled this exception using a catch block. Everything is good until here
Next - there is another action which tries to insert to a different table. Before executing this action - Hibernate still has the old action (failed DB insert) as part of the action queue and tries to execute it one more time. It fails with same Unique constraint error.
I do not want to clear the session as it would clear the cache and other details as well. Is there any way to clear the associated action query which was failed before?
Solution 1:[1]
Either don't insert something which violates constrains or loosen the constrains. Database constrains should not be handled but avoided.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Valerij Dobler |
