各位好,今天用了一下IN()操作符,但是报错,请大家帮忙看一下,我用的是Hibernate 3以上版本。代码摘要:String itemsql = "from Item i in(i.bids) b where b.amountCurrency >200 ";
List itemList = secondSession.createQuery(itemsql).list();
错误摘要:Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: unexpected token: in near line 1, column 28 [select i from hello.Item i in(i.bids) b where b.amountCurrency >200 ]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)

解决方案 »

  1.   

    写错了给你例句from DomesticCat cat where cat.name in ( 'Foo', 'Bar', 'Baz' )
      

  2.   

    from Item i in(i.bids) b where b.amountCurrency >200 这个例子我按书上改的,是使用From子句实现内连接的一种方式。
    大概意思是出出价金额大于200的所有已出价的商品和出价的信息。
      

  3.   

    这种语法明显是错的,可能是印刷错误, from Item i in(i.bids) b ,这个 b 是什么,可以放在这里吗? HQL 和 SQL及其类似,你SQL能这样写吗? 这个 b 应该是前面那句查询出来的子集的别名。( select ..... from Item i in(i.bids) ) b where b.amountCurrency >200  看看加上红色部分的括号,把 b 当作结果集试试。
      

  4.   

    原书例句:    select i from Item i in(i.bids) b where i.description like '%Foo' and b.amount>100Hibernate实战(第二版),第478页,页首部。有这本数的朋友可以看看。
      

  5.   

    IN前面应该有个逗号。
    FROM Item i, IN(i.bids) b WHERE b.amountCurrency > 200
      

  6.   


    OK! 测试后通过。Hibernate 实战(第二版),书中摘要:     HQL和JPA QL提供另外一种语法,用于在FROM子句中连接集合,并给它分配一个别名。
         这个IN()操作符在更早版本的EJB QL中就出现了。
         它的语义与普通集合连接的一样。
        from Item i,in(i.bids) b 生成了与上面的示例中用from Item i join i.bids b一样的内部连接。谢谢各位的支持!
      

  7.   

    这书,一个逗号要人命,呵呵,看你们的讨论,我也有收获了,正找hql 是否能in操作呢。呵呵