gpt4 book ai didi

eclipselink - 如何在我的 JPQL 查询中使用 UNION 和 Order by Clause

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

我在我的项目中使用 eclipse 链接作为 JPA。我正在使用的当前 jar 是 eclipselink-2.5.2。来回答我的问题, 我想在 UNION 组合中使用 Order by。我的 JPQL 查询如下所示

select req from Rqst req  
WHERE (req.Applc =:SYSTEM_IDENTIFIER1 AND req.procesTyp =:PROCESS_TYPE1 AND UPPER(req.updtBy) =:UPDATED_BY1)
AND req.stat <> :ignoreDeletedRequests
UNION
select req from Rqst req
WHERE (req.Applc =:SYSTEM_IDENTIFIER2 AND req.procesTyp =:PROCESS_TYPE2 AND UPPER(req.updtBy) =:UPDATED_BY2)
AND req.stat <> :ignoreDeletedRequests
UNION
select req from Rqst req
WHERE (req.Applc =:SYSTEM_IDENTIFIER3 AND req.procesTyp =:PROCESS_TYPE3 AND UPPER(req.updtBy) =:UPDATED_BY3)
AND req.stat <> :ignoreDeletedRequests
ORDER BY req.rqstId ASC

没有 Order by 它对我有用。但是当我使用 Order by 时,我得到 The query contains an malformed ending.

任何人都可以帮助我,我被困了很长时间。

最佳答案

我遇到了和你一样的问题。我通过像这样使用 Collection.sort() 解决了这个问题:

Collections.sort(listObjects, new Comparator<Object[]>() {

@Override
public int compare(final Object[] record1, final Object[] record2) {
int c;
c = convertTime(record1[0].toString()).compareTo(convertTime(record2[0].toString()));
if (c == 0) {
c = record1[1].toString().compareTo(record2[1].toString());
}
if (c == 0) {
c = record1[2].toString().compareTo(record2[2].toString());
}
if (c == 0) {
c = new Long(Long.parseLong(record1[3].toString())).compareTo(Long.parseLong(record2[3].toString()));
}
if (c == 0) {
c = ((Date) record1[4]).compareTo(((Date) record2[4]));
}
if (c == 0) {
c = ((Date) record1[5]).compareTo(((Date) record2[5]));
}
if (c == 0) {
c = new Long(Long.parseLong(record1[6].toString())).compareTo(Long.parseLong(record2[6].toString()));
}
return c;
}

});

您可以使用 Collention.sort() 对多个字段进行排序;

关于eclipselink - 如何在我的 JPQL 查询中使用 UNION 和 Order by Clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28871323/

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