2013-06-29 5 views
1

J'utilise jpa eclipselink pour la base de données mysql, j'ai besoin d'insérer en bloc une liste contenant plus de 6000 objets. Mais seulement 215 lignes sont insérées dans la base de données et aucune exception n'est levée.insert en vrac utilisant jpa eclipselink

ici est mon code

private EntityManagerFactory emf = null; 

    private static final String PERSISTENCE_UNIT_NAME = "Cation"; 

    private static EntityManagerFactory factory; 

    public EntityManager getEntityManager() { 
     return emf.createEntityManager(); 
    } 

factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); 
     EntityManager em = factory.createEntityManager(); 
     try { 
      em.getTransaction().begin(); 
      for (int i = 0; i < sgmlList.size(); i++) { 
       // Getting the object from the list by using loop 
       SGML sgml = sgmlList.get(i); 
       em.persist(sgml); 
      } 
      em.getTransaction().commit(); 
      FacesContext.getCurrentInstance().addMessage(null, 
        new FacesMessage("SGML imported successfully")); 
     } catch (Exception ex) { 

     } finally { 
      if (em != null) { 
       em.close(); 
      } 
     } 

quelqu'un peut me aider à résoudre ce problème plz.

Répondre

3

Votre blog catch ignore simplement les exceptions levées. Peut-être devriez-vous vous connecter pour les voir réellement. :)

0

JPA insert en vrac est comme ça ..

public void bulkinsertEditores(List<Editore> editories) { 
try { 
EntityManagerFactory emf = EntityManagerFactoryClass.getEntityManagerFactoryInstance(); 
EntityManager em = emf.createEntityManager(); 
em.getTransaction().begin(); 
int ip = 0; 
for (Editore ed : editories) { 
ip = ip + 1; 
em.persist(ed); 
if ((ip % 20) == 0) { 
    em.flush(); 
    em.clear(); 
    } 

} 

    em.getTransaction().commit(); 
} catch (Exception e) { 
e.printStackTrace(); 
}