0 Replies Latest reply on Sep 15, 2008 4:03 PM by Steven Gold

    JBoss/Hibernate/JTA & Bulk Insert

    Steven Gold Newbie

      I am looking for a way to do a bulk insert of thousands of objects using JBoss and Hibernate. I currently have an injected EntityManager with a JTA PersistenceContext in a Stateless Session Bean and am doing something like

      for(int i = 0; i < num; i++){
      MyObject myObject = createMyObject(num, ...);

      (in a try/catch block) which is slow.

      I have unsuccessfully tried to use entityManager.getTransaction() to begin, commit, etc. transactions. I have also unsuccessfully tied to convert the EntityManager to a HibernateEntityManager and use Hibernate transactions. I've also tried to use @TransactionAttribute(TransactionAttributeType.REQUIRED) but it made no significant difference (it's slightly faster).

      Is there a way to save multiple objects in a "single" database call, or at least a few?

      BTW, Having something like entityManager.persist(collection) would be nice.