Hibernate 后端标准查询包含:where(1=1) 是什么意思?

Hibernate backend criterion query contains : where(1=1) what does it means?

执行以下代码行:

Criteria cri = dc.getExecutableCriteria(this.session);

            int start = (p.getCurrentPage() - 1) * p.getPageSize();
            int end = p.getPageSize();
            cri.setFirstResult(start);
            cri.setMaxResults(end);

            result = cri.list();

当 cri.list() 执行时,我从日志中检查 sql 休眠执行,

Hibernate: select * from 
( 
select this_.ID as ID175_0_, 
his_.NAME as NAME175_0_,
 this_.DESCRIPTION as DESCRIPT3_175_0_, 
 this_.VALUE as VALUE175_0_, 
 this_.STATE as STATE175_0_, 
 this_.ATTR1 as ATTR7_175_0_, 
 this_.ATTR2 as ATTR8_175_0_, 
 this_.ATTR3 as ATTR9_175_0_, 
 this_.ATTR4 as ATTR10_175_0_, 
 this_.ATTR5 as ATTR11_175_0_, 
 this_.LASTUSER as LAST12_175_0_, 
 this_.LASTTIME as LAST13_175_0_, 
 this_.POLICY as POLICY175_0_ 
 from TestDB.TestTable this_ 
  where (1=1) 
 and 
 this_.VALUE18 is null 
 order by lower(this_.NAME) asc, this_.ID desc ) where rownum <= ?

where (1=1) over here 是什么意思??

what does where (1=1) over here means??

这与根本没有 WHERE 子句是一样的。所有行都通过测试。

您会在 auto-generates WHERE 子句的代码中看到这一点,并且即使没有条件也希望始终输出一个,或者总是以那种 all-rows-match 条件开始,然后通过 AND 添加任何其他内容(因此代码不必跟踪是否在标准或 AND 之前输出 WHERE)。