0 Replies Latest reply on Apr 27, 2005 5:02 AM by grzegorz.knapczyk

    EntityManager - loading a bunch of records with .persist wit

    grzegorz.knapczyk

      I need to import data from tab seperated text file. Each row is one record - ArchiveTr7Record


      @Entity
      public class ArchiveTr7Record implements java.io.Serializable
      {
      ...
      }
      

      I have implemented the following business method within @Stateless bean:

      @Stateless
      public class ArchiveTr7DAOBean implements ArchiveTr7DAO {
       @Inject private EntityManager em;
      
       boolean importTabSeperatedFile(String importFile)
       {
       // openning input file
       (...)
       String l = lineReader.readLine();
       while (l != null) {
       ArchiveTr7Record rec = parseRecord(l);
       if (rec!=null)
       {
       em.persist(rec);
       em.flush();
       }
       l = lineReader.readLine();
       }
      
       return true;
       }
      }
      

      When I execute method importTabSeperatedFile:
       ArchiveTr7DAO archiveTr7 = (ArchiveTr7DAO) ctx.lookup(ArchiveTr7DAO.class.getName());
       archiveTr7.importTabSeperatedFile( fileName );
      

      The data are not flushed to the database within the loop, and finally the JBOSS server is OutOfMemory! How should I implement it?