弹簧数据在>之后立即执行插入和删除行

时间:2018-04-29 22:11:10

标签: spring hibernate rest spring-data

我有一个带有端点的Spring Boot / Data Api,用于删除记录。当我发送请求时,Hibernate日志如下:2018-04-29 18:05:04.920 DEBUG 8928 --- [nio-8080-exec-2] org.hibernate.SQL : select max(id) from registration 2018-04-29 18:05:04.950 DEBUG 8928 --- [nio-8080-exec-2] org.hibernate.SQL : insert into registration (e_id, first_name, last_name, tech, id) values (?, ?, ?, ?, ?) 2018-04-29 18:05:04.953 TRACE 8928 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [tbc328] 2018-04-29 18:05:04.953 TRACE 8928 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [VARCHAR] - [Fon] 2018-04-29 18:05:04.953 TRACE 8928 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARCHAR] - [Bom] 2018-04-29 18:05:04.953 TRACE 8928 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [VARCHAR] - [Java] 2018-04-29 18:05:04.953 TRACE 8928 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder : binding parameter [5] as [INTEGER] - [29] 2018-04-29 18:05:04.960 DEBUG 8928 --- [nio-8080-exec-2] org.hibernate.SQL : delete from registration where id=? 2018-04-29 18:05:04.960 TRACE 8928 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [INTEGER] - [29]

它会在同一记录之后发出insert然后是delete吗?我要删除的记录仍然有200个http代码?

Repo Here(启动控制器):https://github.com/BillyCharter87/Tech-O-Dex-API/blob/dac8fe092ddb8131b5069b8bc5467bfa80048d9e/complete/src/main/java/com/TechODex/controller/RegistrationController.java#L25-L30

发帖人详情。

URL:localhost:8080/delete

请求正文:{ "firstName": "Fon", "lastName": "Bom", "eId": "tbc328", "tech": "Java" }

由于

1 个答案:

答案 0 :(得分:0)

在创建新记录并将其传递给删除时。 Hibernate检查对象是否已经持久化。如果没有,首先它将尝试持久化对象,然后它将删除它。 与您的情况一样,对象标识符id为空。

有关详情,请点击此处hibernate delete event