JPA 检测到可重入刷新
我对 spring 2.5 的 jpa 的 openjpa 实现没有什么问题。我的 dao 方法:
@Transactional
public User getUserByName(final String name) {
return (User) getEntityManager().createQuery("select u from User as u where u.name = :name").setParameter("name", name).getSingleResult();
}
返回 org.springframework.dao.InvalidDataAccessApiUsageException:
org.apache.openjpa.persistence.InvalidStateException: Detected reentrant flush. Make sure your flush-time instance callback methods or event listeners do not invoke any operations that require the in-progress flush to complete.
at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1904)
at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1679)
at org.apache.openjpa.kernel.QueryImpl.isInMemory(QueryImpl.java:956)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:838)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:779)
at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:525)
at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:254)
at org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:317)
at org.jpa.dao.UserDao.getUserByName(UserDao.java:71)
//EDIT EntityManager 设置:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
<property name="showSql" value="false"/>
</bean>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.OpenJpaDialect"/>
</property>
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
如何获取 EntityManager? dao类中:
@PersistenceContext(type = PersistenceContextType.EXTENDED)
protected EntityManager entityManager;
出了什么问题?有什么想法吗?
I have little problem with openjpa implementation of jpa with spring 2.5. My dao method:
@Transactional
public User getUserByName(final String name) {
return (User) getEntityManager().createQuery("select u from User as u where u.name = :name").setParameter("name", name).getSingleResult();
}
returns org.springframework.dao.InvalidDataAccessApiUsageException:
org.apache.openjpa.persistence.InvalidStateException: Detected reentrant flush. Make sure your flush-time instance callback methods or event listeners do not invoke any operations that require the in-progress flush to complete.
at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1904)
at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1679)
at org.apache.openjpa.kernel.QueryImpl.isInMemory(QueryImpl.java:956)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:838)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:779)
at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:525)
at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:254)
at org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:317)
at org.jpa.dao.UserDao.getUserByName(UserDao.java:71)
//EDIT
EntityManager settings:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
<property name="showSql" value="false"/>
</bean>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.OpenJpaDialect"/>
</property>
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
How do you obtain an EntityManage? In dao class:
@PersistenceContext(type = PersistenceContextType.EXTENDED)
protected EntityManager entityManager;
What is wrong? Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有同样的问题,并修改我的主键实体:
也许可以帮助你。
I have the same problem, and modify my entity for the primary key:
maybe can help you.