gpt4 book ai didi

hibernate - org.hibernate.QueryException : illegal attempt to dereference collection

转载 作者:行者123 更新时间:2023-12-03 02:19:05 25 4
gpt4 key购买 nike

我正在尝试执行以下 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 的属性。

Product 是此Collection元素属性。

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

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

关于hibernate - org.hibernate.QueryException : illegal attempt to dereference collection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24750754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com