- 论坛徽章:
- 0
|
public List findByProperty(String propertyName, Object value) {
log.debug("finding Teacher instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Teacher as model where model."
+ propertyName + "= ?";
Query queryObject = HibernateSessionFactory.getSession().createQuery(queryString);
queryObject.setParameter(0, value);
//HibernateSessionFactory.closeSession();
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
特别注意标注颜色的代码,只要加上,就会出现HibernateException这个异常。本想着要在每一个函数中打开session后要关闭session,这次却适得其反,以后要特别注意......
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/43804/showart_357045.html |
|