Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » preventing on jpa exception setRollbackOnly
preventing on jpa exception setRollbackOnly [message #904910] Wed, 29 August 2012 11:17 Go to next message
Igor B is currently offline Igor BFriend
Messages: 9
Registered: July 2012
Junior Member
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 #904985 is a reply to message #904910] Wed, 29 August 2012 14:12 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
If any process fails in JPA, it leaves your transaction potentially in an inconsistent state - it really shouldn't be continued. Transactions are meant to be an all or nothing approach; the application should deal with the exception and retry the entire transaction process if required. If service2 is in the same transaction and it were able to continue after say a failed flush attempt, its view of the data would be corrupted and you couldn't be sure how much of service1 was actually being commited. So if they are independent of each other, then they should be in separate transactions.
Re: preventing on jpa exception setRollbackOnly [message #905299 is a reply to message #904985] Thu, 30 August 2012 05:45 Go to previous message
Igor B is currently offline Igor BFriend
Messages: 9
Registered: July 2012
Junior Member
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
Previous Topic:Copygroup
Next Topic:Attempting to retry query
Goto Forum:
  


Current Time: Wed Apr 24 22:00:24 GMT 2024

Powered by FUDForum. Page generated in 0.03706 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top