HQL错误:加入的预期路径 [英] HQL ERROR: Path expected for join
本文介绍了HQL错误:加入的预期路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试此查询的变体,似乎无法实现这一点。我也引用了这篇文章:加入的预期路径! Nhibernate错误并且似乎无法将相同的逻辑应用于我的查询。我的用户
对象有一个 UserGroup
集合。
I keep trying variations of this query and can't seem to make this happen. I've also referenced this post: Path Expected for Join! Nhibernate Error and can't seem to apply the same logic to my query. My User
object has a UserGroup
collection.
I理解查询需要引用对象中的实体,但是从我看到的我是... ...
I understand that the query needs to reference entities within the object, but from what I'm seeing I am...
@NamedQuery(
name = "User.findByGroupId",
query =
"SELECT u FROM UserGroup ug " +
"INNER JOIN User u WHERE ug.group_id = :groupId ORDER BY u.lastname"
)
推荐答案
select u from UserGroup ug inner join ug.user u
where ug.group_id = :groupId
order by u.lastname
作为命名查询:
@NamedQuery(
name = "User.findByGroupId",
query =
"SELECT u FROM UserGroup ug " +
"INNER JOIN ug.user u WHERE ug.group_id = :groupId ORDER BY u.lastname"
)
使用HQL语句中的路径,从一个实体到另一个实体。请参阅有关HQL和连接的Hibernate文档了解详情。
Use paths in the HQL statement, from one entity to the other. See the Hibernate documentation on HQL and joins for details.
这篇关于HQL错误:加入的预期路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文