Hi Georg, When creating dynamic SQL, it's a common practice to use the "1 = 1" in the WHERE clause to know that there is always at least one conditional. This way, you can automatically use the "AND" with the other conditions since the "1 = 1" always evaluates to True. Normally, this "1 = 1" gets optimized out by the SQL processor on the database side, so it shouldn't be hurting anything.
Another common usage is to force a result set to be returned. If the only condition that evaluates to True is "1 = 1", then an empty result set is returned instead of a null or an exception (depending on the query). Are you finding an issue with this "1 = 1" clause, or are you just curious why it's there? The above explanations are just in general. I have not dug into the specific case you outline below, but my guess it's related to the first explanation above. Kevin On Tue, May 17, 2011 at 12:02 PM, Georg Nozicka <[email protected]>wrote: > Hello, > > we are using OPENJPA 2.0.0 and have defined with the criteria api a query > which produces the following sql code (actually the sql uses more columns, > I > tried to remove some of them to make the sql easier to read): > > SELECT T0.OID, T0.X, T3.BEZOID, T3.OID, T3.GEMNR > FROM TABLE0 T0 > INNER JOIN TABLE1 T1 ON T0.OID = T1.UOID > INNER JOIN TABLE2 T2 ON T0.OID = T2.BEZOID > LEFT OUTER JOIN TABLE2 T3 ON T0.OID = T3.BEZOID > WHERE (T1.Y LIKE ? ESCAPE '\' AND T2.GEMNR LIKE ? ESCAPE '\' AND 1 = 1) > > [params=(String) abc%, (String) 801%] > > The questions are > - why is at the end “AND 1 = 1” appended? > - is it possible to avoid somehow the "AND 1 = 1" and if, how? > > Best Regards, > Georg > > > -- > View this message in context: > http://openjpa.208410.n2.nabble.com/Criteria-API-AND-1-1-in-WHERE-Clause-tp6373899p6373899.html > Sent from the OpenJPA Users mailing list archive at Nabble.com. >
