Hibernate queries slow down drastically after an entity is loaded in the session

后端 未结 3 1295
甜味超标
甜味超标 2020-12-28 21:03

I\'m using Hibernate EntityManager, and am experiencing a weird slowdown in my Hibernate queries. Take a look at this code:

public void testQuerySpeed() {
           


        
3条回答
  •  旧巷少年郎
    2020-12-28 21:36

    I had essentially the same problem (query inside a loop). I proceeded a profiling verification with JProfiler...the execution of my interested method spent 572 seconds and hibernate dirty-checking takes 457 seconds of this time (about 80%). Amazing, isn't it? I must say that I had a lot of entities managed by EntityManager. If I introduce em.flush()/em.clear() or em.setFlushMode(FlushModeType.COMMIT) in the offending code, the performance problem goes away.

    profiler result is available at http://img1.imagilive.com/0110/hibernate_dirty_checking_bad_perfomances0ce.png

提交回复
热议问题