Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
org.hibernate.QueryException:取消引用集合的非法尝试_Hibernate_Hql_Jpa 2.0_Dereference_Jpa 2.1 - Fatal编程技术网

org.hibernate.QueryException:取消引用集合的非法尝试

org.hibernate.QueryException:取消引用集合的非法尝试,hibernate,hql,jpa-2.0,dereference,jpa-2.1,Hibernate,Hql,Jpa 2.0,Dereference,Jpa 2.1,我正在尝试执行以下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.billPro

我正在尝试执行以下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)

billProductSet
是一个
集合
。 因此,它没有名为
product
的属性

产品
是此
集合
元素的属性

您可以通过加入集合而不是取消引用来解决问题:

选择计数(*)
来自BillDetails bd
加入bd.billProductSet bps
其中bd.client.id=1
和bps.product.id=1002

因为billProduct是一对多映射,并且一个BillDetails实体中有多个billProduct实体,所以您不能在查询中取消引用它。您必须将BillDetails模型连接到billProduct,并使用where CLUSE筛选结果。

如果billProductSet为@JoinTable,则在我的测试中不起作用,而且关系是ManyToMany。@Stony它确实与
@JoinTable
@ManyToMany
一起工作。我现在正在运行它。仅供参考:在我的例子中,我已经在做集合的联接,但是没有给它一个别名,它将无法工作。谢谢您可以添加类的定义吗?它们是否包含关系定义?