java - issue with hibernate "session is closed" -
i can't save rows file excel in database, because error :
exception in thread "main" org.hibernate.sessionexception: session closed!
my code :
annotationconfiguration conf = new annotationconfiguration(); conf.addannotatedclass(etudiant.class); conf.configure("hibernate.cfg.xml"); new schemaexport(conf).create(true, true); sessionfactory factory = conf.buildsessionfactory(); session session = factory.getcurrentsession(); for(int i=3;i<tab.length;i++){ session.begintransaction(); etudiant.setnom(tab[i]); i++; etudiant.setprenom(tab[i]); i++; etudiant.setage(tab[i]); session.save(etudiant); session.gettransaction().commit(); }
anyone have idea plz ?
you fulling first level cache. clearing , flushing cache periodically should considered when doing bulk insert. committing in each iteration slow down insertion.
you have this..
13.1. batch inserts when making new objects persistent flush() , clear() sessionregularly in order control size of first-level cache. session session = sessionfactory.opensession(); transaction tx = session.begintransaction(); ( int i=0; i<100000; i++ ) { customer customer = new customer(.....); session.save(customer); if ( % 20 == 0 ) { //20, same jdbc batch size //flush batch of inserts , release memory: session.flush(); session.clear(); } } tx.commit(); session.close();
Comments
Post a Comment