I am having a problem with duplicate entry handling using hibernate in a web application.
Scenario:
I am running a batch process which does a sequence of Hibernate insert and update operations. The batch process can be triggered by multiple concurrent requests which could lead to duplicate inserts.
Problem: When a duplicate entry ConstraintViolationException happens , how do I ignore the exception and continue,since session gets into an inconsistent state after the exception and needs to be rolledback completely. (This is based on my understanding that since Hibernate does not guarantee the time of execution of the sql operations, only the sequence,an exception needs to be rolled back)
Requirement:I want to use database constraint violation rather than application layer handling of duplicate entries.
Please let me know if you have ever faced this scenario before or if you have any suggestions.
Thanks,
Naveen.
|