[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - JBoss/Hibernate/JTA & Bulk Insert

sgold do-not-reply at jboss.com
Mon Sep 15 16:03:08 EDT 2008


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, ...);
    entityManager.persist(myObject);
  }
 
(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.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4176612#4176612

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4176612



More information about the jboss-user mailing list