0

Executing below line of codes:

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();

when cri.list() executes I have check for the sql hibernate executes from the logs,

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 <= ?

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

user3363047
  • 41
  • 2
  • 11
  • 3
    It means "Here is a space where an extra condition might go, but since we don't have one, here's something that is always true." – khelwood Jun 20 '19 at 09:20
  • https://stackoverflow.com/questions/242822/why-would-someone-use-where-1-1-and-conditions-in-a-sql-clause – Reimeus Jun 20 '19 at 09:26

1 Answers1

0

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

It's the same as not having a WHERE clause at all. All rows pass the test.

You'll see this in code that auto-generates WHERE clauses and either wants to always output one even if there are no criteria, or always starts out with that kind of all-rows-match criterion and then adds on any others via AND (so the code doesn't have to keep track of whether to output WHERE prior to the criterion or AND).

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875