hibernate的回调函数,以及

hibernate的帮助文档搜索: 迭代式获取结果(Iterating results)
 
public int countObjectsByHQL(final String HQLStr, final Object[] parmaters)
			throws DaoException {
		//log.info("数据层:执行HQL语句进行数据库查询,获得查询结果对象集合 countObjectsByHQL(String["+HQLStr+"], Object[] ["+parmaters+"])");
		try {
			Object num = getHibernateTemplate().execute(
					new HibernateCallback() {
						public Object doInHibernate(Session session)
								throws HibernateException, SQLException {
							Query query = session.createQuery(HQLStr);
                            log.info("session="+session);
                            log.info("session="+session.connection());session.connection();
							if (parmaters != null && parmaters.length > 0) {
								for (int i = 0; i < parmaters.length; i++) {
									query.setParameter(i, parmaters[i]);
								}
							}
						return query.iterate().next();
						}
					
					});
			return Integer.valueOf(num.toString());
		} catch (Exception e) {
			throw new DaoException(DaoException.ERRORCODE_QUERY, e);
		}
	}

 query.iterate().next();  返回的是值。

你可能感兴趣的:(Hibernate,exception,session,String,object,query)