1

Does anyone know if it's possible to make CMP JTA work on plain CDI beans? The goal is just to inject a DAO bean (which is NO EJB) into a JSF bean, annotate a method with some kick-ass annotation and make it work out of the box. Some thing like this :

@Named
public class ClusterController {

    @Inject
    private ClusterDAO clusterDAO;

    /**
     * A simple proxy method
     * @param cluster cluster to be saved to the DB
     */

    @Transactional(value = Transactional.TxType.REQUIRES_NEW)
    public void createCluster(Cluster cluster) {
        clusterDAO.saveEntity(cluster);
    }
}

This @Transactional(value = Transactional.TxType.REQUIRES_NEW) does not do the trick (I'm using JBOSS EAP 6). I get :

Caused by: javax.persistence.TransactionRequiredException: JBAS011469: Transaction is required to perform this operation (either use a transaction or extended persistence context)
    at org.jboss.as.jpa.container.AbstractEntityManager.transactionIsRequired(AbstractEntityManager.java:692) [jboss-as-jpa-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
    at org.jboss.as.jpa.container.AbstractEntityManager.persist(AbstractEntityManager.java:562) [jboss-as-jpa-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Anton
  • 1,001
  • 9
  • 23

1 Answers1

2

Not in plain Java EE 6 without some plumbing. According to this answer, by standard this is possible in Java EE 7 with JTA 1.2. You can get a quick picture about JTA 1.2 in the Aquarium.

So, a number of options remain:

IMHO, I'd stick with the standard and write/use an interceptor (if change of architecture/specification/vendor is really not the option). You can hopefully do an easy swap for JTA 1.2 transactions in case of a future migration.

You can find more detail in linked Q&As.

Community
  • 1
  • 1
Jurri
  • 318
  • 2
  • 8
  • Thanks. I've implemented CDI interceptor and it works like a charm. Sadly that there is no built-in solution in EE6. – Anton Jun 16 '14 at 21:15
  • 2
    EJB is a built-in solution. It's neat, efficient and standard. Don't shy away from it! – Yuri Jun 17 '14 at 08:30