I would like to globally disable dirty checking in my application (spring data, hibernate).
My goal is that JPA generates update/insert queries only when I explicitly call myRepo.save()
or myRepo.myUpdateQuery()
.
All my entities have final fields and unmodifyiable collections, so I really do not need dirty checking. I always handle updates explicitly.
Still, I get massive performance problems because JPA generates redundant update queries every time a field gets lazy-loaded.
Solutions I have seen so far (no success):
Use FlushMode=MANUAL. This is an overkill since I will have to make sure
flush()
gets called manually. Huge refactoring I cannot afford.Use readonly transactions. This would also block my explicit save/modifying query calls. I want those to keep working.
Detach the entities. This will has extra side effects such as not being able to perform further lazy-loads, which is a nogo. Also, it will require huge refactoring. For the most part, I do not even have access to EntityManager since I am using spring data repositories.
Use Stateless Sessions. Not an option since things like Lazy Loading will also get disabled.