连接所需的 HQL 路径(连接同一个表时)
我正在尝试获取两个不同设备的测量对,并在相同的时间戳上连接。在 SQL 中,这按预期工作:
select
leftItem.Timestamp, leftItem.Value, rightItem.Value
from
DataTable leftItem
inner join DataTable rightItem
on leftItem.Timestamp = rightItem.Timestamp
where
leftItem.Device = 1 and rightItem.Device = 2
但如果我尝试将其转换为 HQL:
select
left, right
from
DataTable as left
inner join DataTable as right
on left.Timestamp = right.Timestamp
where
left.Device = 1 and right.Device = 2
我得到一个 NHibernate.Hql.Ast.ANTLR.SemanticException:
Path expected for join!
How do I specify a “path” to the same table ?
I am trying to get pairs of measurement for two different devices, joined on equal Timestamps. In SQL, this works as expected:
select
leftItem.Timestamp, leftItem.Value, rightItem.Value
from
DataTable leftItem
inner join DataTable rightItem
on leftItem.Timestamp = rightItem.Timestamp
where
leftItem.Device = 1 and rightItem.Device = 2
But if I try to convert it to HQL:
select
left, right
from
DataTable as left
inner join DataTable as right
on left.Timestamp = right.Timestamp
where
left.Device = 1 and right.Device = 2
I get a NHibernate.Hql.Ast.ANTLR.SemanticException:
Path expected for join!
How do I specify a "path" to the same table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 HQL 中,连接只能在实体之间的关联上完成。如果您想要连接其他内容,唯一的可能性是在 where 子句中进行连接:
In HQL, joins can only be done on associations between entities. If you want a join on something else, the only possibility is to make the join in the where clause: