Bulk Updates Provide Performance Benefits: Problem 1: Outdated 1st Level Cache
Bulk Updates Provide Performance Benefits: Problem 1: Outdated 1st Level Cache
em.createNativeQuery(
"UPDATE person p SET firstname = firstname || '-changed'")
.executeUpdate();
log.info("Detach PersonEntity");
em.flush();
em.detach(p);
em.createNativeQuery(
"UPDATE person p SET firstname = firstname || '-changed'")
.executeUpdate();
p = em.find(PersonEntity.class, 1L);
www.thoughts-on-java.org
Use native queries to perform bulk updates
Problem 2: Not part of the entity life cycle
The native UPDATE statement is executed in the database and
doesn’t use any entities. This provides performance benefits, but it
also avoids the execution of any entity lifecycle methods or entity
listeners.
If you use a framework like Hibernate Envers or implement any code
yourself that relies on lifecycle events, you have to either avoid native
UPDATE statements or implement the operations of your listeners
within this specific use case.
www.thoughts-on-java.org