标签:
原因不明
区别
public long countByCriteria() { Long count = (Long) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session)throws HibernateException, SQLException { Criteria criteria = session.createCriteria(getPersistentClass()); return criteria.setProjection(Projections.rowCount()).uniqueResult(); } }); if (null == count) { return 0; } else { return count.longValue(); } }
偶尔出错
public long countByDetachedCriteria(final DetachedCriteria detachedCriteria) { Long count = (Long) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = detachedCriteria.getExecutableCriteria(session); return criteria.setProjection(Projections.rowCount()).uniqueResult(); } }); if (null == count) { return 0; } else { return count.longValue(); } }
detachedCriteria.getExecutableCriteria 偶尔出错
标签:
原文地址:http://www.cnblogs.com/yuyutianxia/p/4747377.html