带有LEAST和GREATEST函数的JPA

带有LEAST和GREATEST函数的JPA

本文介绍了带有LEAST和GREATEST函数的JPA CriteriaQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,我需要使用LEAST和GREATEST函数连接两个表,但使用JPA CriteriaQuery。这里是我试图复制的SQL ......

I am have a problem where i need to join two tables using the LEAST and GREATEST functions, but using JPA CriteriaQuery. Here is the SQL that i am trying to duplicate...

select * from TABLE_A a
inner join TABLE_X x on
(
  a.COL_1 = least(x.COL_Y, x.COL_Z)
  and
  a.COL_2 = greatest(x.COL_Y, x.COL_Z)
);

我曾看过和 ,但是在试图了解如何创建 Expression< T> 以传递给任一函数方面遇到困难。

I have looked at CriteriaBuilder.least(..) and greatest(..), but am having a difficult time trying to understand how to create the Expression<T> to pass to either function.

Predicate greatestPred = cb.equal(pathA.get(TableA_.col2),
                    cb.function("greatest", String.class,
                            pathX.get(TableX_.colY), pathX.get(TableX_.colZ)));

这篇关于带有LEAST和GREATEST函数的JPA CriteriaQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 04:02