0 Replies Latest reply on Sep 7, 2010 2:56 PM by Scott Johnson

    Seam Managed EntityManager vs EntityManagerFactory.createEntityManager

    Scott Johnson Newbie

      I noticed a performance issue with deleting an complicated object in my system that was spread across 15 database tables.  Because of the relationships, we have to actually perform 8 delete statements before the actual home.remove() is called.  All the code uses the EntityManager named queries:




             Query delete = entityManager.createNamedQuery("deleteDocuments");
               delete.setParameter("carrierId", carrier.getId());
               delete.executeUpdate();



      If I use the injected EntityManager the total time to delete this object is 3.5-4.7 seconds.  The actual execution of the sql in the database is less than 2ms per query.


      If I inject the EntityManagerFactory and get the manager off it, and do my own transactions the time is 3.5ish seconds for the first object, but then falls into the 13ms range after that.  I don't understand why. 


      I use the same entityManager across all the delete queries, the only difference is if it was injected or from the injected factory.  Does anyone know why??


      Specs:
      Seam 2.2.0 GA,
      Tomcat 6.0.2,
      Java 1.6