-
1. Re: restart transaction
pgmjsd May 28, 2009 1:17 PM (in response to benitojuarez)I don't think JTA supports that, but even if it did the constraint violation would happen again unless you did something differently (e.g. make sure the constraint isn't violated). You're going to have to figure out how to avoid violating the constraint anyway, so why not just do it in the code explicitly rather than catching exceptions?
-
2. Re: restart transaction
benitojuarez May 29, 2009 10:25 AM (in response to benitojuarez)Thats simply impossible because u cant guarantee, what another process don't change the data between the check and the db-insert.
Where must be a useful exception handling for this case.
-
3. Re: restart transaction
pgmjsd May 29, 2009 1:33 PM (in response to benitojuarez)
Benito Juarez wrote on May 29, 2009 10:25:
Thats simply impossible because u cant guarantee, what another process don't change the data between the check and the db-insert.I've used database locks to do that. Not impossible, but it has some consequences. Anyway, that's off topic.
Hibernate also supports optimistic locking, and will throw a specific exception when a conflict occurs (another transaction changed the data while the current transaction is in progress). In this case, you usually want to notify the user and give them the opportunity to overwrite the data. Of course this would happen in a new transaction.
You could do a similar thing with constraint violations.