Hi,

I am trying to use transactions (JTA) and JPA with Aries blueprint but I did 
not manage to make it work.

I don't want to use XA datasource because I only access a single database. So 
In my JPA persistence.xml file I have something like :
<persistence-unit name="test">
        
<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/testdb)</jta-data-source>
...

My blueprint.xml contains :
<bean id="personService"
        class="test.service.impl.PersonServiceImpl">
        <tx:transaction method="*" value="Required"/>
        <jpa:context property="entityManager" unitname="test"/>
</bean>

I have written a test to check transaction's rollback, using a transactional 
method like the following :

public class PersonServiceImpl implements PersonService {
...   
    public void createPerson(Person person) {
        entityManager.persist(person);
        entityManager.flush();
        
        throw new RuntimeException("exception");
    }
}

I was expecting that the created person would not be written to the database 
after calling "createPerson" because of the Exception, but it is not the case ! 
The person object is persisted in the database.
It appears that the underlying JDBC Connection has an autocommit property set 
to "true", so rollback is impossible. I thought transaction manager would take 
care of JDBC connection autocommit, but it is not the case.

The result is the same with OpenJPA and Hibernate.

Am I missing something related to JTA ?

Thanks for your help.

-- 
Nicolas Dutertry 
HR Access - http://www.hraccess.com 


Reply via email to