Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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
Java 当从外部资源更新表时,SpringData JPA不会刷新或清除缓存_Java_Spring Boot_Jpa_Repository_Entitymanager - Fatal编程技术网

Java 当从外部资源更新表时,SpringData JPA不会刷新或清除缓存

Java 当从外部资源更新表时,SpringData JPA不会刷新或清除缓存,java,spring-boot,jpa,repository,entitymanager,Java,Spring Boot,Jpa,Repository,Entitymanager,我正在使用SpringBoot Jpa与DB表进行交互,在我的Jpa存储库中,我得到的Jpa Entity的旧版本在其他应用程序从外部更新该特定数据库表时未更新,Jpa无法提供更新的数据集。我尝试使用EntityManager.clear、EntityManager.GetEntityManager.Factory.getCache.ReceiveAll;但他们中没有一个在工作 最后,我必须从entityManagerFactory创建一个新的entityManager对象,并运行本机SQL以获

我正在使用SpringBoot Jpa与DB表进行交互,在我的Jpa存储库中,我得到的Jpa Entity的旧版本在其他应用程序从外部更新该特定数据库表时未更新,Jpa无法提供更新的数据集。我尝试使用EntityManager.clear、EntityManager.GetEntityManager.Factory.getCache.ReceiveAll;但他们中没有一个在工作

最后,我必须从entityManagerFactory创建一个新的entityManager对象,并运行本机SQL以获得更新的输出。但这对于我的项目来说不是一个好的实践,因为它使我的JPA依赖于本机SQL。因此,请让我知道我是否缺少或应该做些什么来反映运行时JPA存储库中的最新更改。 或者是否有任何方法可以从新创建的entitymanager对象运行JPA存储库

 entityManager.getEntityManagerFactory().getCache().evictAll(); //Autowired from persistenceContext
        entityManager.clear();
        EntityManager em=emf.createEntityManager();

我认为您应该添加以下代码:

entityManager.flush

尝试向服务添加@Transactional注释


另外,请确保您有一个实体实例。

尝试过,但仍然没有运气请共享更多详细信息,以便我们提供帮助。