High-performance Java Persistence.pdf Fixed
entityManager.createQuery( "update Order o set o.status = :status where o.date < :date") .setParameter("status", Status.CANCELLED) .executeUpdate();
For many Java developers, Hibernate (and JPA) is a double-edged sword. On one hand, it abstracts away the tedious JDBC boilerplate and allows us to navigate a database using an object-oriented paradigm. On the other hand, it is notorious for being a "black box" that can silently cripple application performance if not handled with care. High-performance Java Persistence.pdf
A common mistake is to use entities for all database operations. If you only need to update the status of 50 orders, do not load 50 Order entities into the Persistence Context, dirty check them, and let Hibernate generate 50 update statements. entityManager