Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.0
Hi, i am using Hibernate with Tomcat 5 and using HibernateUtil
git from caveat Emptor when adding data i some times get session closed error the code below written is for batch insertion
but when doing this operation i am getting the error session is closed
plz go through the code and tell me is there any problem in that
because i have been stuck with this error regularly .
public static boolean createCoordinators(String catid, int[] userids,
boolean recurse)
{
System.out.println("printing from create coordinators");
String[] tempIds = null;
String[] categoryids = null;
CategoryReviewer categoryReviewer = null;
if(recurse)
{
try{
tempIds = getSubCategoriesId(catid);
}catch(CategoryNotFoundException ex)
{
ex.printStackTrace();
return false;
}
categoryids = new String[tempIds.length+1];
categoryids[0] = catid;
for(int k = 0 ; k < tempIds.length ; k++ )
{
categoryids[k+1] = tempIds[k];
}
}
else{
categoryids = new String[1];
categoryids[0] = catid;
}
HibernateUtil.beginTransaction();
try{
for(int j=0 ; j < categoryids.length ; j++)
{ System.out.println("printing from first forloop");
for(int i= 0 ; i < userids.length ; i++)
{
System.out.println("Printing from Second loop");
categoryReviewer = new CategoryReviewer();
categoryReviewer.setId(UniqueIdGenerator.getUniqueId());
categoryReviewer.setCategoryId(categoryids[j]);
categoryReviewer.setReviewerId(userids[i]);
HibernateUtil.getSession().save(categoryReviewer);
}
}
HibernateUtil.commitTransaction();
}catch(HibernateException ex)
{
ex.printStackTrace();
return false;
}
finally{
HibernateUtil.closeSession();
}
//TODO if this session.close is uncommented then it will show exception Session.closed
return true;
} // end createCoordinators
Thanks in advance
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: