JBoss Community

Re: Correct approach for creating a large number of records

created by John Ament in EJB3 - View the full discussion

well among my issues now is that i'm realizing conceptually, what i'm doing won't work long term.  Basically, I have this method that will insert a collection of objects into the database

 

public void persistAsAGroup(List<Evaluation> evals) {
        StatelessSession session = sf.openStatelessSession();
        for(Evaluation evaluation : evals) {
            logger.info("inserting an eval");
            session.insert(evaluation);
        }
        session.close();
    }

 

Part of my issue with this ended up being a discrepancy between the size of the objects in here and hibernate.jdbc.batch_size.  When they got to the same size, everything worked fine.  I wonder though, should the same code above work correctly if I'm using EntityManager instead of StatelessSession? Why does it generate a new database connection on each insert?

Reply to this message by going to Community

Start a new discussion in EJB3 at Community