日期:2014-05-17  浏览次数:20794 次

Hibernate session问题~
启动tomcat 加载web.xml。 servlet调用 dao中的isHasSysUser()
为什么总输出:
System.out.println("=====第二步:用户不存在");

并没有去执行select,表里有数据的。。
是不是session的问题?


Java code

    public boolean isHasSysUser()throws NoSuchUserException{
        Session session = null;
        //HttpSession session=ServletActionContext.getRequest().getSession();
        try{
            session = Hibernate_Utils.getSession();
            session.createSQLQuery("select t.id from T_MENU t where t.id=1").executeUpdate();
            System.out.println("=====第二步:用户已经存在");
            return true;
        }catch(Exception e){
            System.out.println("=====第二步:用户不存在");
            throw new NoSuchUserException();
        }finally{
                session.close();
        }
    }




------解决方案--------------------
把异常打出来就知道了啊 你都抛走了,,,
------解决方案--------------------
session.createSQLQuery("select t.id from T_MENU t where t.id=1");