Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HibernateSpringBootOneToManyBidirectional has issue with removeBooks method #7

Open
swapy opened this issue Dec 26, 2022 · 1 comment

Comments

@swapy
Copy link

swapy commented Dec 26, 2022

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?

@AnghelLeonard
Copy link
Owner

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants