简体   繁体   中英

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. 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. is there any document says we can delete detached entity in 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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