OpenJPA - Transaction management is not available… (Fuse ESB)

﹥>﹥吖頭↗ 提交于 2019-12-04 16:03:08

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!