5 Replies Latest reply on Aug 30, 2011 3:25 PM by Adam Warski

    Audited entity updates (lots of them) with no EntityManager clear

    Adriano Saturno Newbie

      I was testing Envers performance.


      I created an audited entity Mailmen, with a many-to-many relationship with another audited entyty, Address.


      Mailmen has a simple field called register. (and an Address collection, but lets simplify the code)


      I just created a new instance of Mailmen and edited it 100.000 times:


      configurationOverrides = new HashMap<String, String>();
      emf = Persistence.createEntityManagerFactory("jpa", configurationOverrides);
      entityManager = emf.createEntityManager();
      int MAX_EDITIONS = 1000000;
      carteiroDefault = new Mailman();
      for(int i = 1; i <= MAX_EDITIONS; i++) { 


      It tooks about 6 hours to run this code.


      It gets better or worse depending on MAX_EDITIONS, in a non linear way. Bad.


      But, if I change the for block to this:


           entityManager.find(Mailman.class, carteiroDefault.getId()).setRegister(i);


      It tooks 30 minutes.


      It gets better or worse depending on MAX_EDITIONS, in a linear way. Much better.


      Is it recommended? Clearing entityManager after commits?