题
我有可能有一个父实体的实体。 我想运行此查询:
选择实体,其中entity.parent.id = 9
一些实体的不具有父母(entity.parent = NULL)和N HIBERNATE未能运行此查询(QueryException - 无法解析属性)
我如何使用HQL来获取所有具有与ID 9父母实体的实体,避免了那些家长为空?
(添加entity.parent不为空的entity.parent.id之前= 9周的结果在相同的异常)
有是使用嵌套的SELECT语句的选择,但我不认为这是最有效的解决方案。
解决方案
您缺少在HQL查询from
条款。尝试改写这样的:
from entity where entity.parent is not null and entity.parent.id = 9
不知道,但可能是entity.parent is not null
部分是没有必要的。我想NHibernate的会处理这种情况。
不隶属于 StackOverflow