SessionFactory 执行原生态的SQL语句

    public List<User> getPageIndex(int pageIndex,int topNum){
        String hql = "select top("+topNum+""+")* from " +
                     "(select * from LMY_MYDJM316 a where a.id not in " +
                     "(select b.id from " +
                     "(select top("+ (pageIndex-1)*topNum+""+")* from LMY_MYDJM316)b))c";    
        SQLQuery query  =  sessionFactory.getCurrentSession().createSQLQuery(hql).addEntity(User.class);  
        System.out.println(query.list());
        return query.list(); 
    }


注意createSQLQuery()后面添加的addEntity

参考:http://www.cnblogs.com/biGpython/archive/2012/03/26/2417926.html

原文地址:https://www.cnblogs.com/CBDoctor/p/3723038.html