+ -
当前位置:首页 → 问答吧 → 请教hibernate问题

请教hibernate问题

时间:2011-10-20

来源:互联网

public int getCount1(Company company,Object param)
{
int count = 0;
if (company != null) {
Session session = (Session) em.getDelegate();
Criteria criteria = session.createCriteria(Company.class);
if (company.getCompanyname() != null && company.getCompanyname().trim().length() > 0)
criteria.add(Restrictions.like("companyname", company.getCompanyname(),
MatchMode.ANYWHERE));

count = ((Number) criteria.setProjection(Projections.rowCount())
.uniqueResult()).intValue();
}
return count;
}
割---------
Session session = (Session) em.getDelegate();
这里用EntityManager.getDelegate得到session.
当得到结果count后,要不要手动将session关闭?
service层中,用了spring的@Transactional注解

作者: cwmwss   发布时间: 2011-10-20

这个要!你要调用spring框架下的hibernateTemple,spring才能管理session

作者: aqqbjlgu   发布时间: 2011-10-20

我也不清楚!路过

作者: luobing261314   发布时间: 2011-10-20