gpt4 book ai didi

hibernate - 如何将两列值与 hibernate 限制进行比较

转载 作者:行者123 更新时间:2023-12-04 14:00:12 25 4
gpt4 key购买 nike

我在将 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 那样工作

最佳答案

我知道这是一个老问题,但对于寻找答案的人,您可以尝试以下代码:

Criteria cr = session.createCriteria(YourClass.class, "entity1");
cr.add(Restrictions.ltProperty("field1", "field2"));
...

关于hibernate - 如何将两列值与 hibernate 限制进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49997793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com