org.hibernate.QueryException:非法尝试解引用集合 [英] org.hibernate.QueryException: illegal attempt to dereference collection

查看:180
本文介绍了org.hibernate.QueryException:非法尝试解引用集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

但它显示

  org.hibernate.QueryException:非法尝试取消引用collection 
[billdetail0_.bill_no .billProductSet]带有元素属性引用[product]
[select count(*)from iland.hbm.BillDetails as bd where bd.billProductSet.product.id = 1001 and bd.client.id = 1]
在org.hibernate.hql.ast.tree.DotNode $ 1.buildIllegalCollectionDereferenceException(DotNode.java:68)
在org.hibernate.hql.ast.tree.DotNode.checkLhsIsNotCollection(DotNode.java:558)


解决方案

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

Product 是元素的一个属性收集



您可以通过加入集合来解决问题,而不是解除引用

 

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


I am trying following hql query to execute

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

But it is showing

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 is a Collection. As such, it does not have an attribute named product.

Product is an attribute of the elements of this Collection.

You can fix the issue by joining the collection instead of dereferencing it:

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

这篇关于org.hibernate.QueryException:非法尝试解引用集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆