users@glassfish.java.net

RE: From NetBeans bundle version to server

From: Wim Verreycken <wim_at_pizzastop.be>
Date: Tue, 26 Aug 2008 15:51:55 +0200

Hi Mauro,

No. joinTransAction() should be called after all transactions but before
closing the Entity Manager. This has the effect of committing all queued
transactions to the DB at once (even if there is only one).

It might be easier to use CMP with annotations like I did in the example.
This has the effect of not having to rollback transactions in case of
exceptions since it will be done automagically.
You will have to use
@TransactionAttribute(TransactionAttributeType.REQUIRED)
however to trigger the automatic rollback feature.

I remember a very good article about all this but I can't seem to find it
anymore. Let me see if I can dig it up from my bookmarks.

In the meantime let me know if it helps pls.

Wim

-----Original Message-----
From: Mauro Chiarugi - Dogma Systems [mailto:mauro.chiarugi_at_dogmasystems.it]

Sent: dinsdag 26 augustus 2008 15:23
To: users_at_glassfish.dev.java.net
Subject: Re: From NetBeans bundle version to server

Wim Verreycken ha scritto:
> OK.
>
> Seems you need to call the JPA entityManager.joinTransaction() for it to
> join JTA transaction if the EntityManager itself is defined outside the
> transaction.
>

Hi Wim,

thank you for your help. I've changed my code in this manner:
        <code>

        EntityManager entityManager =
javax.persistence.Persistence.createEntityManagerFactory("MyRentStorePU").cr
eateEntityManager();
       
         try {

             entityManager.joinTransaction(); // New line

             entityManager.getTransaction().begin();
             entityManager.persist(cliente);
             entityManager.getTransaction().commit();
       </code>

Is it correct?
I obtain the same exception :-(

In a previous email you suggest to change persistence.xml using JTA
instead JPA. I've noticed that I'm just using JTA. I post my
persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

  <persistence-unit name="MyRentStorePU" transaction-type="JTA">

    <jta-data-source>jdbc/myrentstore</jta-data-source>
    <class>it.myrent.store.entity.Clienti</class>
    <class>it.myrent.store.entity.CreditCard</class>
    <class>it.myrent.store.entity.Ordini</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="toplink.ddl-generation" value="create-tables"/>
      <property name="toplink.logging.level" value="FINE"/>
    </properties>

  </persistence-unit>
</persistence>

What should I do?

Thanks in advance,
Mauro Chiarugi

-- 
Mauro Chiarugi
Dogma Systems Srl:
http://www.dogmasystems.it
MyRent, Car Rental Software:
http://www.myrent.it
http://www.myrent.es
http://www.myrent.eu
Email:	mauro.chiarugi [at] dogmasystems.it
Tel :	+39 071 90 90 188
Fax :   +39 071 250 99 63
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: users-help_at_glassfish.dev.java.net