从具有多个预测的分离有限制的一列只获取一列

发布于 2025-02-09 16:44:50 字数 842 浏览 3 评论 0原文

我有以下代码获取具有最新日期的“ Andamento”对象(我称为日期 - >数据)。

DetachedCriteria criteriaAndamento = DetachedCriteria.forClass(Andamento.class);
criteriaAndamento.setProjection(Projections.projectionList()
        .add(Projections.max("data").as(null))
        .add(Projections.groupProperty("processo").as("id"))
);
criteriaAndamento.add(Restrictions.sqlRestriction("DATE_FORMAT(`data`, '%d/%m/%Y') like '" + filter.getFilterValue().toString() + "%'"));
criteria.add(Property.forName("id").in(criteriaAndamento));

但是在这一行中,代码:criteria.add(property.forname(“ id”)。在(criteriaandamento)中);它给出以下错误:

ERROR SqlExceptionHelper:129 - Operand should contain 1 column(s)...

因此,它期望脱离符号只有1列。但是,由于我需要两个预测,我只能选择一个列?还是删除另一个?

PS:我已经删除了“最大”投影并起作用,因此我需要某种方法来仅从此分离有限核管中选择“ Processo”列。

I have the following code to get the object which has the "Andamento" with the latest date (I have called date -> data).

DetachedCriteria criteriaAndamento = DetachedCriteria.forClass(Andamento.class);
criteriaAndamento.setProjection(Projections.projectionList()
        .add(Projections.max("data").as(null))
        .add(Projections.groupProperty("processo").as("id"))
);
criteriaAndamento.add(Restrictions.sqlRestriction("DATE_FORMAT(`data`, '%d/%m/%Y') like '" + filter.getFilterValue().toString() + "%'"));
criteria.add(Property.forName("id").in(criteriaAndamento));

But in this line of code: criteria.add(Property.forName("id").in(criteriaAndamento)); it gives the following error:

ERROR SqlExceptionHelper:129 - Operand should contain 1 column(s)...

So it expects the detachedCriteria to have only 1 column. But since I need both projections, how can I select only one column? Or maybe remove the other?

ps: I have removed the "max" projection and it works, so I need some way to select only the "processo" column from this detachedCriteria.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文