-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: net.sf.hibernate.impl.SessionImpl unclosed connection
PostPosted: Wed Feb 23, 2005 1:05 pm 
Beginner
Beginner

Joined: Wed Jul 21, 2004 8:12 pm
Posts: 35
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1.8

Code between sessionFactory.openSession() and session.close():

public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

ActionErrors errors = new ActionErrors();
DynaActionForm dynaForm = (DynaActionForm) form;
Transaction tx = null;
HibernateUtil util = null;
Session session = null;
ActionUtil aUtil = ActionUtil.getInstance();

try {

ViewBean bean = new ViewBean();
String author = (String) dynaForm.get(Constants.AUTHOR);
String title = (String) dynaForm.get(Constants.COMMENT_TITLE);
String comment = (String) dynaForm.get(Constants.COMMENT);
String categoryId = (String) dynaForm.get(Constants.CATEGORY);
String excluded = (String)dynaForm.get(Constants.EXCLUDED);

Collection products = aUtil
.getArrayToCollection((String[]) dynaForm
.get(Constants.PRODUCT));
Collection platforms = aUtil
.getArrayToCollection((String[]) dynaForm
.get(Constants.PRODUCT));

aUtil.setError(author, "Author is required", errors);
aUtil.setError(title, "Comment title is required", errors);
aUtil.setError(comment, "Comment is required", errors);

if (!errors.isEmpty()) {
saveErrors(request, errors);
return (mapping.findForward(Constants.FAILURE1));
}

Release newRelease = new Release();
newRelease.setAuthor(author);
newRelease.setComment(comment);
newRelease.setTitle(title);

if(excluded == null || excluded.trim().length() == 0)
newRelease.setExcluded(false);
else
newRelease.setExcluded(true);

util = HibernateUtil.getInstance();
session = util.getSession();
tx = util.startTransaction(session);

CategoryDAO cDAO = new CategoryDAO();



PlatformDAO platDAO = new PlatformDAO();
newRelease.setPlatforms(platDAO.getPlatformsByIds(platforms,session));

ProductDAO prodDAO = new ProductDAO();
newRelease.setProducts(prodDAO.getProductsByIds(products,session));

newRelease.setCreated(new Timestamp(System.currentTimeMillis()));

Category rCategory = cDAO.addReleaseToCategoryById(Long.parseLong(categoryId),newRelease,session);
bean.setReleaseCategoryName(rCategory.getName());
bean.setReleaseCategoryId(rCategory.getId());
bean.setReleaseComponentName(rCategory.getParentCategory().getName());

Collection release = new Vector();
release.add(newRelease);
bean.setRelease(release);

util.commitTransaction(tx);
util.closeSession(session);

request.setAttribute(Constants.REQUEST_BEAN, bean);
} catch (Exception e) {
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
"message.detail", e.getMessage()));
saveErrors(request, errors);
util.rollbackTransaction(tx);
util.closeSession(session);
return (mapping.findForward(Constants.FAILURE1));

}

return (mapping.findForward(Constants.SUCCESS1));

}//end save

Name and version of the database you are using: DB2 8.2

I do not know why I get the warning net.sf.hibernate.impl.SessionImpl unclosed connection, forgot to call close() on your session? , I am closing the session. In my close session method, I have tried to different variations but I get the same warning. Here are the two versions I have used:

public void closeSession(Session s) {
try {
if (s != null){
if(s.connection() != null)
s.connection().close();
s.close();

}

} catch (HibernateException ex) {
throw new InfrastructureException(ex);
} catch (SQLException e) {
throw new InfrastructureException(e);
}
}


and

public void closeSession(Session s) {
try {
if (s != null){
s.close();

}

} catch (HibernateException ex) {
throw new InfrastructureException(ex);
} catch (SQLException e) {
throw new InfrastructureException(e);
}
}
I know the warning is outputed because the hibernate is doing the clean up for me. However; I am closing all the sessions, it bewilder me why? Anyone can give me a hint.

regards,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.