web-dev-qa-db-ja.com

org.hibernate.QueryException:コレクションを逆参照する不正な試み

次のhqlクエリを実行しようとしています

SELECT count(*) 
  FROM BillDetails as bd
 WHERE bd.billProductSet.product.id = 1002
   AND bd.client.id                 = 1

しかし、それは示しています

org.hibernate.QueryException: illegal attempt to dereference collection 
[billdetail0_.bill_no.billProductSet] with element property reference [product] 
[select count(*) from iland.hbm.BillDetails as bd where bd.billProductSet.product.id=1001 and bd.client.id=1]
    at org.hibernate.hql.ast.tree.DotNode$1.buildIllegalCollectionDereferenceException(DotNode.Java:68)
    at org.hibernate.hql.ast.tree.DotNode.checkLhsIsNotCollection(DotNode.Java:558)
54
xrcwrn

billProductSetCollectionです。そのため、productという名前の属性はありません。

Productは属性です要素のこのCollectionの。

結合コレクション参照解除の代わりに itで問題を修正できます:

SELECT count(*) 
  FROM BillDetails        bd 
  JOIN bd.billProductSet  bps 
 WHERE bd.client.id       = 1
   AND bps.product.id     = 1002
115
kostja

billProductは1対多マッピングであり、1つのBillDetailsエンティティからの多くのbillProductエンティティがあるため、クエリでそれを逆参照することはできません。

0
J.K