i am working on a play 1.2.4 project and i have 4 jobs running in intervals, fetching bulk data (from webservice) and saves them to the database.
My current bulk insert method is like this:
org.hibernate.Session session =
(org.hibernate.Session)MyEntityModel.em().getDelegate();
Transaction tx = session.beginTransaction();
int i = 0;
for(Sales obj:sales)
{
convertToModelAndSave(obj);
i++;
if(i%100==0)
{
tx.commit();
session.flush();
session.clear();
tx=session.beginTransaction();
}
}
session.disconnect();
i am simply disconnecting the session after job is done.
I am wondering if this is enough for me, do i really need to disconnect the session (which gives me exceptions in the program). Will my database connection pool be release after disconnect?