HQL Path expected for join (when joining 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 expecte开发者_如何学Cd for join!
How do I specify a "path" to the same table?
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:
select left, right
from
DataTable as left, DataTable as right
where
left.Timestamp = right.Timestamp
and left.Device = 1
and right.Device = 2
精彩评论