Java Spring:如何查看repository.delete方法影响了多少个实体/行? [英] Java Spring: How to see how many entities/rows are affected by a repository.delete method?

查看:224
本文介绍了Java Spring:如何查看repository.delete方法影响了多少个实体/行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序(使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆