persistence@glassfish.java.net

Fw: How to commit a JTA Transaction

From: Andrei Ilitchev <andrei.ilitchev_at_oracle.com>
Date: Mon, 26 Jun 2006 15:25:59 -0400

Hi Ali,

JPA doesn't provide JTA - rather JPA may work with JTA, which is typically provided by an application server.
Container-manaded JTA transaction is started / committed automatically by the application server (when transactional method on a session bean starts / exits).
Alternatively the user may obtain user transaction from the app. server (typically through JNDI):

UserTransaction transaction = (UserTransaction) context.lookup(app_server_specific_user_transaction_jndi_name);
tarnsaction.begin();
EntityManager em = entityManagerFactory.getEntityManager();
em.persist(pNumber);
em.close();
transaction.commit();

  ----- Original Message -----
  From: ali aslan
  To: persistence_at_glassfish.dev.java.net
  Cc: Andrei Ilitchev
  Sent: Friday, June 23, 2006 3:19 AM
  Subject: How to commit a JTA Transaction


  Hi,

  I have configured my Toplink to run with own JTA Transaction,DataSource ServerPlatform...


  I am trying to persist a Object. I am not getting an error but the object is not in the Database. I think I am Committing my UserTransaction(XAConnection) but this will not commit my JTA Transaction.

          EntityManager em = getEntityManager();

          UserTransactionImpl.begin();

          em.joinTransaction();

          em.persist(pNumber);

          userTransactionImpl.commit();

          em.close();

  Anyone who knows how to commit the JTA Transaction.


          em.getTransaction().commit() does not work because

          em.getTransaction() returns a EntityTransaction which does not work with a JTA
          Transcation.



  Thanks