public List<TblIllnessInfo> getInessInfo(String code,String type) {
// TODO Auto-generated method stub
Session session = null;
List<TblIllnessInfo> illnesslist = new ArrayList();
try{
session = this.getSessionFactory().openSession();
String hql = " select illness from TblIllnessInfo illness where illness.alphabet=? ";
//session.r
Query query = session.createQuery(hql);
query.setParameter(0, code);
if(!query.list().isEmpty()){
illnesslist = (List<TblIllnessInfo>)query.list();
}
}catch(RuntimeException e){
log.error("save failed", e);
}finally{
session.close();
}
return illnesslist;
}
以上是源码,不知道有没有错误的地方或者是不规范的地方,多次执行后就会报
WARN - unclosed connection, forgot to call close() on your session?
请问大家问题出在哪里了
// TODO Auto-generated method stub
Session session = null;
List<TblIllnessInfo> illnesslist = new ArrayList();
try{
session = this.getSessionFactory().openSession();
String hql = " select illness from TblIllnessInfo illness where illness.alphabet=? ";
//session.r
Query query = session.createQuery(hql);
query.setParameter(0, code);
if(!query.list().isEmpty()){
illnesslist = (List<TblIllnessInfo>)query.list();
}
}catch(RuntimeException e){
log.error("save failed", e);
}finally{
session.close();
}
return illnesslist;
}
以上是源码,不知道有没有错误的地方或者是不规范的地方,多次执行后就会报
WARN - unclosed connection, forgot to call close() on your session?
请问大家问题出在哪里了
老紫竹帮我看一下我的问题呗http://topic.csdn.net/u/20090105/11/277a3f6d-b11c-4e05-9698-5e61784daddd.html
public boolean isDvSetup(AddDocinfoForm eq) {
// TODO Auto-generated method stub
Session session = null;
boolean bool = false;
Transaction tran =null ;
try{
session = this.getSessionFactory().openSession();
tran = session.beginTransaction();
DvSetup setup = (DvSetup)session.load(DvSetup.class, 1);
setup.setForumUserNum(setup.getForumUserNum()+1);
setup.setForumLastUser(eq.getAccounts());
session.saveOrUpdate(setup);
tran.commit();
bool = true;
}catch(RuntimeException e){
if(tran!=null){
tran.rollback();
}
log.error("save failed", e);
}finally{
if(session!=null && session.isOpen()){
session.close();
}
}
return bool;
}
这个是分页查询的方法
public List findLeave(String eim,String type,Integer start ,Integer end,String num) {
// TODO Auto-generated method stub
final String usereim = eim;
final String usertype = type;
final Integer userstart = start;
final Integer userend = end;
final String num1 = num;
return this.getHibernateTemplate().executeFind(new HibernateCallback(){
public List doInHibernate(Session session) throws HibernateException, SQLException {
// TODO Auto-generated method stub
List list = new ArrayList();
tool t = new tool();String hql = "select mess.id,mess.title,mess.datetime,m.id.name,mess.readstate from TblLeaverMessage mess,Mem m where mess.sendEim=? and mess.receiveaEim=m.id.uid";
Query query = session.createQuery(hql).setFirstResult(userstart).setMaxResults(userend);
query.setParameter(0, usereim);
if(!query.list().isEmpty()){ int num = query.list().size();
for(int i=0;i<num;i++){
Object[] obj = (Object[])query.list().get(i);
HashMap map = new HashMap();
map.put("messid", obj[0]);
map.put("title", obj[1]);
map.put("datetime", obj[2]);
map.put("name", obj[3]);
map.put("readstate", obj[4]);
list.add(map);
}
}
return list;
}
});
}
看看是这两个方法的错误吗?
根据错误提示可以看的出
应该是session没有关闭
建议在获取数据库连接,创建session的方法之前
加个if判断语句,来判断一下session是否关闭
要是没有先关闭再建立新的session
你试试