Hibernate-SpringBoot
Hibernate-SpringBoot copied to clipboard
HibernateSpringBootOneToManyBidirectional has issue with removeBooks method
Hi,
Thanks for awesome book.
HibernateSpringBootOneToManyBidirectional has helper method removeBooks.
@Transactional
public void deleteAllBooksOfAuthor() {
Author author = authorRepository.findByName("Joana Nimar");
author.removeBooks(); // use removeBooks() helper
}
But if you see carefully, it calls delete for each book entity. Can we optimize it somehow to call like IN queries instead?
Also purpose of these helper methods is to call on managed entities or detached ones only?
Hi,
I'm glad that you liked the book. Well, you probably need a helper as deleteViaBulkIn(). Could you check it in the book? The challenge is to keep the Persistence Context in sync. The helper methods from entities are for managed entities. When the entities are detached, you can perform any query as long as you know what you are doing. There is no Persistence Context present, so no sync is needed. I hope it helps :)