JBoss Community

Is it possibile open an UserTransaction from a client ?

created by Stefano Gallina in EJB3 - View the full discussion

Hi all,

 

I have a Session bean:

 

@Stateless

@TransactionManagement(TransactionManagementType.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 a Java the following code :

 

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

   userTx.begin();

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

   userTx.commit();

 

 

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 ?

Cheers.

 

            warxsg

Reply to this message by going to Community

Start a new discussion in EJB3 at Community