简体   繁体   English

Spring 数据 jpa 查询返回旧数据

[英]Spring Data jpa query returning old data

We have created a spring boot project using.我们已经创建了一个 spring 引导项目使用。 Our application interacts with oracle database.我们的应用程序与 oracle 数据库交互。 We have created a set of jpa-repositories in which we are using findAll, findOne and other custom queries method.我们创建了一组 jpa 存储库,我们在其中使用 findAll、findOne 和其他自定义查询方法。

We are facing a problem.我们正面临一个问题。 Following are the steps to reproduce it:以下是重现它的步骤:

Fire a read query on db using spring-boot application.使用 spring-boot 应用程序在 db 上触发读取查询。 Now Manually change the data in oracle using oracle-console for the records which are returned by above read query.现在使用 oracle-console 手动更改 oracle 中的数据,用于上述读取查询返回的记录。 Now again fire the same read query using application.现在再次使用应用程序触发相同的读取查询。 After step 3, we should have received the modified results of step 2, but what we got was the data before modification.在第3步之后,我们应该已经收到了第2步的修改结果,但我们得到的是修改前的数据。 Now if we again fire the read query using application, It gives us correct values.现在,如果我们再次使用应用程序触发读取查询,它会为我们提供正确的值。 We are not using any kind of cache in our application.我们没有在我们的应用程序中使用任何类型的缓存。

While debugging I found out that jpa-repository code is calling database and it fetches the latest result.在调试时,我发现 jpa-repository 代码正在调用数据库并获取最新结果。 But when this call return back to our application service, it has the old data.但是当这个调用返回到我们的应用服务时,它有旧数据。

Please help us identify the possible cause of it.请帮助我们确定可能的原因。

As your question is little abstract to understand I would suggest below.由于您的问题不太抽象,因此我将在下面提出建议。

Check how your database transactions are working.检查您的数据库事务是如何工作的。 Seems like in Step 2 your application is in the previous transaction so hibernate is not trying to access your database again for the same key as per Hibernate cache mechanism.似乎在第 2 步中,您的应用程序位于前一个事务中,因此 hibernate 不会尝试再次访问您的数据库,以获得与 Hibernate 缓存机制相同的密钥。

However in Step 3 your application might be starting a new transaction for which hibernate is asking the database again.但是,在第 3 步中,您的应用程序可能正在启动一个新事务,hibernate 再次询问数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM