Speed Up Your JPA Transactions
June 19th, 2007
JPA is a new standardized Java persistence system that takes the best parts of the current persistence technologies. Recently while using JPA, I had noticed that large transactions took increasingly longer to process. It turned out that by default, JPA cross checks a pending query with all managed entities to ensure that the query is up to date. To disable this default behaviour and shoulder the object management yourself, you can do the following:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("YOUR_PU");
EntityManager em = emf.createEntityManager();
em.setFlushMode(FlushModeType.COMMIT); // disable auto-management