select top 5 {theme.*} from Theme {theme} where state=1 and type=1 order by newid() 改成select top 5 (theme.*) from Theme theme where theme.state=1 and theme.type=1 order by theme.newid()之后用hql语句查询 

解决方案 »

  1.   

    Query sqlquery=sess.createSQLQuery(sql,"theme",Theme.class); 
      

  2.   

    用Criteria,改用这个,进行查询,试试?
      

  3.   

    String sql = "select top 5 {theme.*} from Theme {theme} where state=1 and type=1 order by newid() "
    Query sqlquery=sess.createSQLQuery(sql,"theme",Theme.class);
    这样不行?提示什么
      

  4.   

    先在Theme类中提供一个带参数的构造方法:如,
    public Theme(参数1,参数2,参数3,......){
      this.参数1 = 参数1;
      this.参数2 = 参数2;
      ......
    }
    查询语句这样写:
    select top 5 new 你的包名.Theme(参数1,参数2,参数3,......) from Theme t where t.state=1 and t.type=1 order by newid() 
      

  5.   

    楼上的 sql语句里面可以写你的包名这样的东西吗?仅仅是sql语句
      

  6.   

    我刚才看了下api,你看这样搞行不行?
    SQLQuery query = session.createSQLQuery(sql).addEntity("theme",Theme.class)
    把setEntity改成addEntity
      

  7.   

    setEntity是用来给参数赋值的,这个hql里也没参数啊
      

  8.   

    我顶9楼的。。把setEntity改成addEntity就OK了