Hibernate Criteria Restrictions AND combination With in IN 子句

Hibernate Criteria Restrictions AND combination With in IN Clause

我正在使用 Hibernate 4.3.8

我如何使用 Hibernate 限制实现这一点?

SELECT * FROM t1 WHERE ( col_1, col_2 ) IN (( 'a', 'b' ), ( 'c', 'd' ));

如果 col_1col_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'