Java Spring: How to see how many entities/rows are affected by a repository.delete method?

♀尐吖头ヾ 提交于 2019-12-25 08:43:10

问题


Within my application (that uses Spring Data and extending the CrudRepository), I am deleting Entities using:

repository.delete(Dog);

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?


回答1:


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.



来源:https://stackoverflow.com/questions/36021525/java-spring-how-to-see-how-many-entities-rows-are-affected-by-a-repository-dele

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!