gpt4 book ai didi

java - Hibernate后端条件查询包含: where(1=1) what does it means?

转载 作者:行者123 更新时间:2023-12-02 04:11:57 24 4
gpt4 key购买 nike

执行以下代码行:

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() 执行时,我会检查 hibernate 从日志中执行的 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)是什么意思?

最佳答案

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

这与根本没有 WHERE 子句相同。所有行都通过测试。

您将在自动生成 WHERE 子句的代码中看到这一点,并且即使没有条件也希望始终输出一个子句,或者始终以这种全行匹配条件开始,然后添加任何其他条件通过 AND(因此代码不必跟踪是否在条件或 AND 之前输出 WHERE)。

关于java - Hibernate后端条件查询包含: where(1=1) what does it means?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56682782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com