id   =   Integer.parseInt(session.createQuery(sql).list().get(0).toString()); 

解决方案 »

  1.   

    参考下:
    if (dto.getCategoryId() == null) {
    String categoryIdMax = WhbzSer.findMaxCategoryId(rc.getDBSession());
            long l_categoryId = Long.parseLong(categoryIdMax) + 1;
    dto.setCategoryId(new Long(l_categoryId));
    }
    //-DAO里面的方法
    public static String findMaxCategoryId(Session session) throws Exception {
    StringBuffer hql = new StringBuffer();
    hql.append("SELECT MAX(t.categoryId) FROM TExpCategory t");
    String maxId = "0"; List list = PrivilegeDao.queryListByPage(session, hql.toString());
    if (list != null && list.size() > 0) {
    maxId = list.get(0).toString();
    } return maxId;
    }