SessionFactory 执行原生态的SQL语句

    public List 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

你可能感兴趣的:(SessionFactory 执行原生态的SQL语句)