简体   繁体   English

删除独立实体spring jpa Repository接口

[英]Delete detached entity spring jpa Repository interface

I was reading that deleting detached entity will cause IllegalArgumentExcetpion, the entity should be managed to be removed. 我在读,删除分离的实体将导致IllegalArgumentExcetpion,应管理该实体的删除。 However , I'm using spring JPA repository interface and the delete is working on a detached entity , I have created new entity with the ID I want to delete and I got no exception. 但是,我使用的是Spring JPA存储库接口,删除操作正在一个分离的实体上,我已经创建了一个具有要删除ID的新实体,我也没有例外。 is there any document says we can delete detached entity in spring jpa ? 是否有任何文件说我们可以在spring jpa中删除分离的实体? I couldn't find official document. 我找不到正式文件。

在可以使用repository.delete(entity)之前,应调用repository.find(entityID)来防止“分离的实体异常”。

Every entity has id and you can delete deatached entity by id like 每个实体都有ID,您可以按ID删除已拆离的实体,例如

 @Modifying @Query("delete from OwnEntity e where e.id = :id")
 Long deleteById(@Param("id") Long id);

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

相关问题 Spring数据jpa分离实体 - Spring data jpa detached entity Spring JPA - 实体分离? 关于例外? - Spring JPA - entity detached? on exceptions? Spring jpa 存储库返回实体 class 而不是 dto 接口 - Spring jpa repository returns the entity class instead of the dto interface 当保存到存储库而不使用级联时,Spring JPA 获取错误分离实体传递给单向 OneToOne 关系 - Spring JPA get error detached entity passed to persist on unidirectional OneToOne relationship when save to repository without cascade Spring Data Repository:传递给持久化的分离实体 - Spring Data Repository: Detached entity passed to persist 我可以使用 Spring Data JPA 处理多个实体类的单个 JPA 存储库接口吗? - Can I have a single JPA repository interface handling multiple entity classes using Spring Data JPA? 为具有主键的实体定义弹簧数据JPA存储库接口,该主键也是JPA 2.x中的外键 - Defining a spring-data JPA repository interface for entity with primary key that is also a foreign key in JPA 2.x 更新实体spring jpa时的分离实体问题 - detached entity issue when updating entity spring jpa 在JPA和存储库接口中获取实体类 - Getting Entity Class in JPA and Repository Interface 通过将 InMemory 更改为 Spring Data JPA / Mysql 来分离实体 - Detached Entity by changing InMemory to Spring Data JPA / Mysql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM