Klajdi
Klajdi

Reputation: 1

No externally managed transaction is currently active for this thread

I have this method which calls package, stored procedures, but it gives me this error: No externally managed transaction is currently active for this thread.

What should I change or add to fix this?

@Override
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void rebuildIndexes() {
    Query query = getEm().createNativeQuery("BEGIN OFPA_ARCHIVING.rebuild_archiving_indexes; END;");
    query.executeUpdate();
}

Upvotes: 0

Views: 255

Answers (1)

gmanjon
gmanjon

Reputation: 1521

The documentation in https://javaee.github.io/javaee-spec/javadocs/javax/ejb/TransactionAttributeType.html states that

NOT_SUPPORTED

The container invokes an enterprise bean method whose transaction attribute NOT_SUPPORTED with an unspecified transaction context.

You should change the TransactionAttributeType to some value that ensures a transaction. If you are in an EJB class (Stateless, Stateful or Singleton) this is supported by default, so without any annotation you should be good to go.

Which value tonchoose depends on your business case, but tipically you will use:

REQUIRED: This is the default, so.os the same as not using the annotation at all. Usong this means that if the caller of thenmethod doesn't have a transaction a new one will be created.

MANDATORY: The same as before, but if the caller doesn't have a transaction and exception will be thrown (TransactionRequiredException)

or

REQUIRES_NEW: If you want to start and end a transaction with the start and the end of the method.

Upvotes: 0

Related Questions