Spring transactional context doesn't persist data

醉酒当歌 提交于 2019-12-05 11:27:45

In the version of the code that uses the JPA entity manager. Try adding an em.flush() after the em.persist() - all em.persist() does is to attach the entity to the persistence context. The entity is not 'persisted' at that point.

You should not need the em.flush() - but give it a try to see if it helps.

When the transaction ends then the persistence context should automatically be flushed (written to the db).

I have to say you've got quite a complicated setup here - you might need some trial & error to narrow it down. Adding JTA into the mix might not help matters - you could try with 'resource local' in Spring until you get it working. Are there any errors in the logs ?

solved my problem using

org.springframework.orm.jpa.JpaTransactionManager

so your bean should be

 <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" />

hope this work!

Maybe this will help:

In the JNDI case, specify the corresponding JNDI names in this post-processor's "persistenceUnits" map, typically with matching persistence-unit-ref entries in the Java EE deployment descriptor. By default, those names are considered as resource references (according to the Java EE resource-ref convention), located underneath the "java:comp/env/" namespace. For example:

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">
    <property name="persistenceUnits">
        <map>
            <entry key="unit1" value="persistence/unit1"/>
            <entry key="unit2" value="persistence/unit2"/>
        </map>
    </property>
</bean>

From:

http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.html

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