Get more recipes like this one in my new book Hibernate Tips: More than 70 solutions to common Hibernate problems: https://goo.gl/XfywNk
This time I will show you how to detach entities from your persistence context.
As I explained in one of my previous video and in my Hibernate Performance Tuning training: When you need to update or delete a huge number of entities, it is often better to use a JPQL or SQL statement instead of updating one entity after the other. Instead of performing at least one query for each updated entity you then just need to execute 1 query.
But the JPQL or SQL statement also has a disadvantage. Hibernate doesn’t know which database records you’re updating and can’t replicate the changes to the entities stored in the persistence context or 1st level cache. You, therefore, need to do that yourself and detach all entities from the persistence context before you execute the query.
That’s when I always get the same question: How do you detach an entity from the persistence context?
If you like this video, please give me your thumbs up and share it with your friends and co-workers.
Like my channel? Subscribe!
➜ http://bit.ly/2cUsid8
Join the free Member Library:
https://goo.gl/dtyIIC
Read the accompanying post: https://www.thoughts-on-java.org/hibe...
Want to connect with me?
Blog: http://www.thoughts-on-java.org/
Twitter: / thjanssen123
Facebook: / thoughtsonjava
#JPA #Hibernate #HibernateTips