Ok, here is the answer.
Firstly, 2 nice links on JPA Concepts and the Aries JPA Container
RESOURCE_LOCAL
transaction-type="RESOURCE_LOCAL"
is indeed self-managed persistence, and the code should be like this:
EntityManager entityManager = entityManagerFactory.createEntityManager();
...
entityManager.getTransaction().begin();
entityManager.persist(a);
entityManager.persist(b);
entityManager.getTransaction().commit();
Using entityManager.getTransaction()
and entityManager.flush()
both caused exceptions, because I had specified <jpa:context>
.
The correct way to do it is with <jpa:unit>
and EntityManagerFactory
.
<bean id="invoiceDao" class="com.company.project.InvoiceDao">
<jpa:unit unitname="invoicePersistence" property="entityManagerFactory"/>
</bean>
JTA
On the other hand transaction-type="JTA"
is 'container-managed' persistence:
entityManager.persist(a);
entityManager.persist(b);
and it should be configured in blueprint with <jpa:context>
and an EntityManager
.