Does JPA apps using JTA transactions have to invoke transaction.begin() and commit ?

View: New views
1 Messages — Rating Filter:   Alert me  

Does JPA apps using JTA transactions have to invoke transaction.begin() and commit ?

by Rajesh S :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I am trying to run an EJB3 application using EclipseLink as persistence provider. Some of the objects aren't getting persisted. But after I added explicit invokes to entityManager.getTransaction().begin() and entityManager.getTransaction().commit() around the persist calls the objects got persisted. I am using JTA datasource. Incidentally, the same code snippet worked fine without the transaction begin and commit invokes while using hibernate.

Is entityManager.getTransaction().begin() and entityManager.getTransaction().commit() required for JTA connections while using EclipseLink? I expected the provider to handle this for me.
Or am I missing something ? Any help on this ?

Here is the code snippet and the persistence.xml

entityManager.getTransaction().begin();
entityManager.persist(anObject);
entityManager.getTransaction().commit();

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">

        <persistence-unit transaction-type="JTA" name="mypunit">
                <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/DBDataSource</jta-data-source>  

                <class>...</class>
                <class>...</class>
                <class>...</class>
                <exclude-unlisted-classes>true</exclude-unlisted-classes>

                <properties>
                        <property name="eclipselink.logging.level" value="WARNING" />
                        <property name="eclipselink.weaving" value="true" />
                </properties>
        </persistence-unit>
</persistence>

I would appreciate any help / pointers on this.

Thanks in advance,
Rajesh
LightInTheBox - Buy quality products at wholesale price