Search code examples
jpacdijta

Transaction Error JTA DATASOURCE JPA CDI


data-source with JBoss EAP in my project.

For some reason when i try to persist an object i get the error below.

JBAS011469: Transaction is required to perform this operation (either use a transaction or extended persistence context): javax.faces.FacesException: #{back.salvar}: javax.persistence.TransactionRequiredException: JBAS011469: Transaction is required to perform this operation (either use a transaction or extended persistence context)

There is @Transactional method but this method launch the error. Anyone?

@Stateless
@Named
public class BaseDao implements Serializable
{
    private static final long serialVersionUID = -8993128837557701804L;

    @PersistenceContext
    protected EntityManager manager;

    @Transactional
    public void persist(Object object)
    {
        manager.persist(object);
    }

}

PS: All objects are injected with CDI, the manager is injected with the object class org.jboss.as.jpa.container.TransactionScopedEntityManager


Solution

  • As your CDI bean is an EJB stateless session bean, you don't have to use @Transactional annotation here since EJB have Container Managed Transaction (CMT) by default.

    @Transactional is useful to manage transaction transaction on a CDI managed bean (i.e. POJO).