简体   繁体   English

Spring JpaRepository 在 select 之后不执行删除或插入语句

[英]Spring JpaRepository dows not execute delete or insert statements after select

I have a very strange problem.我有一个非常奇怪的问题。 I have a Spring Boot application with a JpaRepository and hibernate to handle persisting simple Java objects.我有一个带有 JpaRepository 和 hibernate 的 Spring 引导应用程序来处理持久的简单 Java 对象。 These only have a number of string properties.这些只有一些字符串属性。 No Relationships, no special subclasses, very very simple.没有关系,没有特殊的子类,非常非常简单。 I am using the Spring Boot 2.3.7.Release.我正在使用 Spring Boot 2.3.7.Release。 I tested this effect both with an H2-Database as well as PostegreSQL.我使用 H2-Database 和 PostegreSQL 测试了这种效果。 Done this hundreds of times before.以前做过数百次。

On my development notebook running on windows 10, everything works as expected - I can save entities, delete them.在我在 windows 10 上运行的开发笔记本上,一切正常 - 我可以保存实体,删除它们。 But when I try to deploy the application on my linux server (centOS), the delete and insert statements are simply not executed.但是当我尝试在我的 linux 服务器(centOS)上部署应用程序时,删除和插入语句根本没有执行。

For example, if I call the save function, I would expect first a select statement (to check, if the entry is already present), followed by insert (as it is not in my case).例如,如果我调用保存 function,我希望首先是 select 语句(检查条目是否已经存在),然后是插入(因为它不是在我的情况下)。 And that's exactly what I see on my notebook.这正是我在笔记本上看到的。 On the server I see the initial select statement is executed, but the following insert is not.在服务器上,我看到执行了初始 select 语句,但没有执行以下插入。 It is not even tried.它甚至没有尝试过。

The same holds true for deleteAll() - I see the select statement, but the following delete statements are missing. deleteAll() 也是如此 - 我看到 select 语句,但缺少以下删除语句。 And I do not get any error message.而且我没有收到任何错误消息。 Nothing.没有什么。 Hibernate is just omitting the delete and insert statements. Hibernate 只是省略了删除和插入语句。

I can insert data into the database manually with the same user used in my application and the program even does pick the saved data up - I can retrieve them and display them.我可以使用我的应用程序中使用的同一用户手动将数据插入数据库,并且程序甚至会选择保存的数据 - 我可以检索它们并显示它们。 So the connection to the database works, the mapping works, it's just as if hibernate is in some kind of read-only mode, omitting all delete and insert statements.因此,与数据库的连接有效,映射有效,就好像 hibernate 处于某种只读模式,省略了所有删除和插入语句。

Any idea about that?有什么想法吗? I already checked all available configurations (that are the same, besides some environment variables, which only provide the passwords).我已经检查了所有可用的配置(除了一些只提供密码的环境变量之外,它们是相同的)。

I am simply running out of ideas where to look.我只是想不出去哪里找。 Thanks a lot in advance!提前非常感谢!

I finally found the solution - another datasource was autoconfigured by a part of the application (spring batch) and it was a race between the two, which one got initialized first.我终于找到了解决方案 - 另一个数据源由应用程序的一部分(弹簧批处理)自动配置,这是两者之间的竞争,其中一个首先被初始化。 On my Laptop the postgres jpa won resulting in a working system, on the server, the other one worked, resulting in the problems.在我的笔记本电脑上,postgres jpa 赢得了一个工作系统,在服务器上,另一个工作,导致了问题。

The only difference I found in the debug log was a longer time for the JPA initialization...我在调试日志中发现的唯一区别是 JPA 初始化的时间更长...

After manually connecting Spring batch to the postgresql, it works.手动将 Spring 批次连接到 postgresql 后,它可以工作。

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

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