[jboss-user] [EJB 3.0] - Duplicate Key / SystemException
do-not-reply at jboss.com
Sun Sep 23 12:05:25 EDT 2007
In my application it's very likely that two entity beans with the same primary key (consisting of a string) get persisted at the same time. If that happens a "duplicate key" exception (PersistenceException/NonUniqueObjectException) is raised and the the current transaction is unfortuantely being rolled back.
The problem is that it does not seem to be possible to recover from this error gracefully. Trying to catch the exception nevertheless rolls back the transaction. I have read, that's because it's an SystemException and that those kind of RuntimeExceptinons always roll back the current transaction.
I have also read that, if we declare those RuntimeExceptions as application exceptions in the ejb-jar xml description and set the rollback tag to false, the current transaction is not being rolled back. I have tried this by inserting the following xml into my ejb-jar, but it does not prevent the transaction from being rolled back:
My application heavily depends on gracefully dealing with those kind of duplicate key exceptions, because I need them to figure out, whether or not a certain entity already exists and I can't use a simple SELECT to find out, because of concurrency issues and I can't use an isolation level of Serializable, because of performance reasons.
How can I make sure that I catch those kind of duplicate key exceptions without the current transaction being rolled back when I call entityManager.persit(myEntityBean) ???
PS: This guy seems to have the same problem
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4087645#4087645
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4087645
More information about the jboss-user