Java Spring:如何查看repository.delete方法影响了多少个实体/行? [英] Java Spring: How to see how many entities/rows are affected by a repository.delete method?
问题描述
在我的应用程序(使用Spring Data
并扩展CrudRepository
)中,我正在使用以下方法删除实体:
Within my application (that uses Spring Data
and extending the CrudRepository
), I am deleting Entities using:
repository.delete(Dog);
这将触发其他表/实体上的Cascade-delete
. (注意:Hibernate
是我的JPA实现)
This triggers a Cascade-delete
on other tables/entities. (note: Hibernate
is my JPA implementation)
是否可以查看已从数据库中删除了多少行/实体?
Is there a way to see how many rows/entities this has deleted from the Database?
推荐答案
不是,至少在JPA级别上不是.如果看一下EntityManager
类(这意味着比Spring Data更深入一步),您将看到它的 delete
方法也可以做到这一点.
It isn't, not at least at JPA level. If you take a look to the EntityManager
class (which means going one step deeper than Spring Data), you'll see its remove
method returns nothing. The delete
metod of the Spring Data Crud repository does it too.
简而言之,这是您必须在事务处理方法中进行管理的内容,如果您要考虑级联操作中可能隐含的相关实体,则甚至需要更多处理.
In short words, that's something you'll have to manage in your transactional methods, even more if you want to take into account the related entities which could be implied in a cascade operation.
这篇关于Java Spring:如何查看repository.delete方法影响了多少个实体/行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!