preventing on jpa exception setRollbackOnly [message #904910] |
Wed, 29 August 2012 07:17  |
Eclipse User |
|
|
|
Hi,
I face the problem with EclipseLink within Weblogic Server and Container Managed Transaction handling. The case as pseudo code is as follows:
SessionBean {
public doBusinessLogic {
try {
call service1; // JPA Read Service which will cause an DatabaseException
} catch (Exception e) {}
call service2; // Here happens a TransactionRolledbackException
}
}
Now my problem is, that even after calling service1 the Exception happens and I catch it for doing nothing, I would like that service2 will be called and finally the doBusinessLogic will be commited normaly whenever service2 does not have an exception.
How can I configure JPA in such a way, so that the following exception does not happen:
java.security.PrivilegedActionException: javax.transaction.TransactionRolledbackException: EJB Exception: : javax.transaction.TransactionRolledbackException: EJB Exception: : weblogic.transaction.internal.AppSetRollbackOnlyException: setRollbackOnly called on transaction
at weblogic.transaction.internal.TransactionImpl.setRollbackOnly(TransactionImpl.java:550)
at weblogic.transaction.internal.TransactionManagerImpl.setRollbackOnly(TransactionManagerImpl.java:332)
at weblogic.transaction.internal.TransactionManagerImpl.setRollbackOnly(TransactionManagerImpl.java:325)
at org.eclipse.persistence.transaction.JTATransactionController.markTransactionForRollback_impl(JTATransactionController.java:160)
at org.eclipse.persistence.transaction.AbstractTransactionController.markTransactionForRollback(AbstractTransactionController.java:198)
at org.eclipse.persistence.internal.jpa.transaction.JTATransactionWrapper.setRollbackOnlyInternal(JTATransactionWrapper.java:77)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.setRollbackOnly(EntityManagerImpl.java:1869)
at org.eclipse.persistence.internal.jpa.QueryImpl.setRollbackOnly(QueryImpl.java:862)
at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:152)
at org.eclipse.persistence.internal.jpa.QueryImpl.getSingleResult(QueryImpl.java:442)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:382)
Any help very welcome,
best regards,
Igor
|
|
|
|
Re: preventing on jpa exception setRollbackOnly [message #905299 is a reply to message #904985] |
Thu, 30 August 2012 01:45  |
Eclipse User |
|
|
|
Hi Chris,
thank you for your answer, you are right in your explenation.
In my pseudo Code doBusinessLogic is one transaction calling service1 and service2 each on it own transaction. So the behaviour is correct, when service1 and service2 as SessionBeans having Transaction attribute "Required" and one of them fail, so the whole transaction (doBusinessLogic) will be marked as Rollback. Now because service1 is only a read-only service, I put the transaction attribute to "NotSupported" and like this it will be excluded from the overall transaction. Even JPA raise an exception within service1, it will not impose doBusinessLogic to be rollbacked. Only the outcome from service2 will decide.
So my problem I could solve using the transaction attribute setting on the SessionBean.
Anyway, I think JPA should have a switch for special cases so that in case of an Exception it will not mark a transaction for rollback and the decision will be up to the SessionBean doing a rollback or not. Alternatively one could also use UserTransaction and handle it in this way.
best regards,
Igor
|
|
|
Powered by
FUDForum. Page generated in 0.04936 seconds