persistence@glassfish.java.net

Re: Fw: How to commit a JTA Transaction

From: ali aslan <aliforummails_at_googlemail.com>
Date: Tue, 27 Jun 2006 08:33:43 +0200

Hi,

thats exactly what is not working.

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

At this point I could retrieve the inserted frame from the DB

em.createQuery("select Object(myObject) from ...";)

and I am retrieveing the inserted Object but after closing the
EntityManager and commiting the transaction I don't get any error and there
is nothing stored in the DB. I am sure to have been checked the right DB.



2006/6/26, Andrei Ilitchev <andrei.ilitchev_at_oracle.com>:
>
> 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 <aliforummails_at_googlemail.com>
> *To:* persistence_at_glassfish.dev.java.net
> *Cc:* Andrei Ilitchev <andrei.ilitchev_at_oracle.com>
> *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
>
>