Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 太平绅士_Hibernate_Jpa_Spring Data - Fatal编程技术网

Hibernate 太平绅士

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

我想在测试中手动刷新JPA缓存。通过spring数据插入记录后,我会执行
.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注入实体管理器。好的,把它作为答案,我会投票表决