问题
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