openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Georg Nozicka <georg.nozi...@nozicka.at>
Subject Re: Criteria API; AND 1 = 1 in WHERE Clause
Date Tue, 28 Jun 2011 14:57:56 GMT
Hello,

I tried to reduce the sample as far as possible. First the code:

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<UnternehmenUrv> cq = cb.createQuery(UnternehmenUrv.class);
Root<UnternehmenUrv> untRoot = cq.from(UnternehmenUrv.class);
cq.select(untRoot);

Join&lt;UnternehmenUrv, UnameHist&gt; unameHistJoin = untRoot.join(
  UnternehmenUrv_.unameHist.getName(), JoinType.INNER);

Join&lt;UnternehmenUrv, Adresse&gt; adresseJoin = untRoot.join(
  UnternehmenUrv_.adressen.getName(), JoinType.INNER);

List<Predicate> predicates = new ArrayList<Predicate>();

ParameterExpression<String> pe = cb.parameter(String.class,
  UnameHist_.unameL.getName());
predicates.add(cb.like(
  unameHistJoin.get(UnameHist_.unameL).as(String.class), pe));

ParameterExpression<String> peStr = cb.parameter(String.class,
  Adresse_.strL.getName());
predicates.add(cb.like(adresseJoin.get(Adresse_.strL).as(String.class),
  peStr));

cq.where(cb.and(predicates.toArray(new Predicate[0])));

TypedQuery<UnternehmenUrv> tq = em.createQuery(cq);

tq.setParameter(UnameHist_.unameL.getName(), "nozick%");
tq.setParameter(Adresse_.strL.getName(), "fadenw%");

return tq.getResultList();

The toString for the CriteriaQuery instance gives the following output:
SELECT u FROM UnternehmenUrv u INNER JOIN u.unameHist ?  INNER JOIN
u.adressen ?  WHERE (u.unameHist.unameL LIKE :unameL AND u.adressen.strL
LIKE :strL)

The jpa trace for the generated SQL is like this:
SELECT t0.OID, t0.UKOID, t0.UNAME, t0.UNTID FROM udbq.TUUNT_UNTERNEHMEN t0
INNER JOIN udbq.TUUNT_UNAME_HIST t1 ON t0.OID = t1.UOID INNER JOIN
udbq.TUUNT_ADRESSE t2 ON t0.OID = t2.BEZOID WHERE (t1.UNAME_L LIKE ? ESCAPE
'\' AND t2.STR_L LIKE ? ESCAPE '\' AND 1 = 1)  [params=?, ?]

Any ideas?

--
View this message in context: http://openjpa.208410.n2.nabble.com/Criteria-API-AND-1-1-in-WHERE-Clause-tp6373899p6525216.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message