Transactions are started via Interceptors.
When you call a method of a bean from inside that bean, the method-call is not intercepted and no Transaction can get started.
You need another Bean and persist in there
@RequestScoped
@Transactional(value = TxType.REQUIRES_NEW)
public class SomeOtherBean{
@PersistenceContext(type = PersistenceContextType.EXTENDED)
EntityManager em;
public void doSomething(){
//retrieve db records
//make changes and commit
//sample
//em.persist(someEntity)
}
}
then you can Inject that bean in your TaskRunner
@ApplicationScoped
@ActivateRequestContext
public class TaskRunner {
@Inject
SomeOtherBean someBean;
...
private void runSchedule() {
someBean.doSomething()
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…