HQL 错误:预期加入的路径 [英] HQL ERROR: Path expected for join

查看:23
本文介绍了HQL 错误:预期加入的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试此查询的变体,但似乎无法实现.我还参考了这篇文章:预期加入的路径!Nhibernate 错误 并且似乎无法将相同的逻辑应用于我的查询.我的 User 对象有一个 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 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屋!

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