1 Reply Latest reply on Mar 26, 2012 3:35 PM by Wolf-Dieter Fink

    Is it possibile open an UserTransaction from a client ?

    Steven Zoster Newbie

      Hi all,


      I have a Session bean:





      The session bean calls an entity bean and save the name and the surname in table called Customer


      I wanted to manage the transaction from a Java Client so  I wrote the following code :


        userTx = (UserTransaction) ctx.lookup("UserTransaction");


          customerCreation.createSimpleCustomer("TestName", "TestSurname");




      When I run my  class I have the error:


      [STDERR] javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction

      [STDERR]           at org.jboss.jpa.deployment.ManagedEntityManagerFactory.verifyInTx(ManagedEntityManagerFactory.java:155)

      [STDERR]           at org.jboss.jpa.tx.TransactionScopedEntityManager.persist(TransactionScopedEntityManager.java:186)

      [STDERR]           at com.allianzppu.b2x.CustomerCreation.createSimpleCustomer(CustomerCreation.java:47)


      If I manage the transaction inside the mehod of my session bean everything works.

      Any suggestion ?




        • 1. Re: Is it possibile open an UserTransaction from a client ?
          Wolf-Dieter Fink Master

          In your case NO.


          The EJB 3.1 spec section 13.6.1 says this for BMT:

          The container must manage client invocations to an enterprise bean instance with bean-managed transaction demarcation as follows.

          When a client invokes a business method via one of the enterprise bean’s client views, the container suspends any transaction that may be associated with the client request...

          This will be similar in earlier versions of the spec.


          If you want to have such behavior use TransactionManagementType.CONTAINER, here it will be possible.