如何比较两个列值与休眠限制

时间:2018-04-24 09:15:47

标签: hibernate hibernate-criteria jointable

我无法将MySQL Query转换为适当的Hibernate代码。具体是以下SQL

select a.id, b.id as id, b.timestamp as timestamp, b.speed as speed from abc a join xyz b on b.abc_id = a.id left xyz b2 on (a.id = b2.abc_id and b.timestamp < b2.timestamp OR b.timestamp = b2.timestamp AND b.id < b2.id))

以上查询运行完美并获得预期结果,但当我尝试转换为Hibernate Criteria时,我不知道下面的代码

(a.id = b2.abc_id and (b.timestamp < b2.timestamp OR b.timestamp = b2.timestamp AND b.id < b2.id))

我已经尝试过以下代码

Criteria criteria = currentSession().createCriteria(Abc.class);
criteria.createAlias("xyz", "b");
criteria.createAlias("xyz", "b2");
criteria.add(Restrictions.le("b.timestamp", "b2.timestamp"));
criteria.add(Restrictions.lt("b.id", "b2.id"));

但它不能按照MySql Query

运行

0 个答案:

没有答案