问题描述
我使用的是 Hibernate 4.3.8
如何使用 Hibernate Restrictions 实现这一点?
SELECT * FROM t1 WHERE ( col_1,col_2 ) IN (( 'a','b' ),( 'c','d' ));
解决方法
如果 col_1
和 col_2
是嵌入式的一部分,您可以像 select e from Entity e where e.embeddable in (:embeddable1,:embeddable2)
一样使用它并相应地传递嵌入式。但请注意,此版本的 Hibernate 尚不支持模拟行值构造函数,因此它取决于您使用的 DBMS(如果可行)。您可以通过执行以下操作来模拟这一点:
select e
from Entity e
where e.col1 = 'a' and e.col2 = 'b'
or e.col1 = 'c' and e.col2 = 'd'