码迷,mamicode.com
首页 > 其他好文 > 详细

detachedCriteria.getExecutableCriteria 偶尔出错

时间:2015-08-21 12:50:35      阅读:970      评论:0      收藏:0      [点我收藏+]

标签:

原因不明

区别

    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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!