Object is not getting persisted using JPA/JTA/JBOSS/CDI

后端 未结 2 1814
情话喂你
情话喂你 2021-01-24 20:18

Please help me to understand why object is not getting persisted with following code. It throws javax.persistence.TransactionRequiredException: JBAS011469: Transacti

相关标签:
2条回答
  • 2021-01-24 20:24

    I'm not too familiar with EJBs, but I believe the problem is that without the @Stateless annotation, the bean is not a EJB, so transactions are not automatically managed. If you need statefulness, use the @Stateful annotation to make a stateful EJB. If you do not want to use EJBs, you have to manually manage your transactions using the EntityManager like so.

    tx = em.getTransaction();
    tx.begin();
    
    // do some work
    ...
    
    tx.commit();
    
    0 讨论(0)
  • 2021-01-24 20:32

    When you declare the bean as @Stateless then the methods in that bean are by default transactional. Transactional methods commit the persistence state when fully executed.

    When you don't have your class annotated with @Stateless methods are not transactional by default and hence you get the mentioned exception.

    0 讨论(0)
提交回复
热议问题