I have a stateless bean resposible for persisting entities to a database. This stateless bean is called by a message bean's onMessage method. The wired thing is that on the first message everything works fine, but on the next message the method responsible for persisting is invoked outside a transaction, even though the method is annotated with REQUIRES_NEW.
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public StateChange persistChange(long deviceId, ...) {
...
StateChange change = new StateChange(...);
em.persist(change);
em.refresh(change); // To provoke the error
return change;
}
Calling refresh triggers the following exception:
Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
Any ideas? I'm fairly new to JTA so I might have missed something important?