Hibernate 太平绅士
我想在测试中手动刷新JPA缓存。通过spring数据插入记录后,我会执行Hibernate 太平绅士,hibernate,jpa,spring-data,Hibernate,Jpa,Spring Data,我想在测试中手动刷新JPA缓存。通过spring数据插入记录后,我会执行.exists()检查,这实际上需要几秒钟的时间,如果存在约束问题,它们只显示在.exists上,而不显示在插入代码本身上 我能做什么?自动连线的SessionFactory存在,但是调用它的getCurrentSession().flush()没有任何作用 <beans profile="test"> <bean id="sessionFactory" class="org.springframe
.exists()
检查,这实际上需要几秒钟的时间,如果存在约束问题,它们只显示在.exists
上,而不显示在插入代码本身上
我能做什么?自动连线的SessionFactory存在,但是调用它的getCurrentSession().flush()
没有任何作用
<beans profile="test">
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
而这:
<bean id="sessionFactory" class="org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
原因
org.hibernate.hibernate异常:未配置CurrentSessionContext代码>好的,我成功地从JPARepository
子类化了我的spring数据
存储库
类,然后使用repo.flush()
注意:警告--刷新刷新所有缓存对象,而不仅仅是存储库管理的对象。因此,如果您的存储库是公共类BookRepo实现了JPARepository
,那么调用BookRepo.flush()
也将刷新所有作者
、阅读器
,以及w/e对象。为什么要使用Hibernate会话进行刷新?使用EntityManager.flush()?使用@PersistenceContext EntityManager em注入实体管理器代码>。好的,把它作为答案,我会投票表决