user330026
user330026

Reputation: 11

Java EE WildFly 8.2 transaction required exception

My application is deployed on WildFly 8.2.

I'm processing a batch.

Method A in Session EJB has required new annotation.

Inside of it I am calling another method, Method B, on the same EJB with another requires new annotation.

This Method B throws runtime exception. Method A catch it and continues.

But next line which deals with JPA update gives transaction required exception.

Basically I don't know why Method B with Required New annotation affects Method A.

It is entity manager on JPA Dao loosing transaction.

How can I make Method B run in isolation and only rollback Method B if exception happened in it.

Upvotes: 0

Views: 820

Answers (1)

user6048742
user6048742

Reputation:

You can use the session context to call the methodB via the EJB container, so the transaction annotation can take effect.

Your EJB should look something like this:

@Resource
SessionContext sessionCtx;
.
.
.
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void methodA() {
    <Your-EJB-Interface> ejbObject = sessionCtx.getBusinessObject(<Your-EJB-Interface>.class);
     ejbObject.methodB();
}

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void methodB....

Upvotes: 3

Related Questions