openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <>
Subject [jira] [Work logged] (OPENJPA-2788) Anonymous parameters are not being picked when adding via CriteriaBuilder
Date Wed, 24 Apr 2019 20:46:00 GMT


ASF GitHub Bot logged work on OPENJPA-2788:

                Author: ASF GitHub Bot
            Created on: 24/Apr/19 20:45
            Start Date: 24/Apr/19 20:45
    Worklog Time Spent: 10m 
      Work Description: michaelwiles commented on pull request #42: [OPENJPA-2788] addressing
issue with anonymous parameters
   So a slight adjustment to the hashcode and equals method of the ParameterExpression.
   Not 100% sure it's right like this but it works.
   I guess I'm not too familiar with the reason for the addition of the hashCode and equals
in the first place.
   The bottom line is that we must include in these hashCode and equals method the ability
to handle the situation where the name is not specified.
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

Issue Time Tracking

            Worklog Id:     (was: 232364)
            Time Spent: 10m
    Remaining Estimate: 0h

> Anonymous parameters are not being picked when adding via CriteriaBuilder
> -------------------------------------------------------------------------
>                 Key: OPENJPA-2788
>                 URL:
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: criteria
>    Affects Versions: 3.1.0
>            Reporter: Michael Wiles
>            Priority: Critical
>          Time Spent: 10m
>  Remaining Estimate: 0h
> Something that is almost certainly introduced via fixes for OPENJPA-2785 and OPENJPA-2733
is that anonymous parameters are not picked up.
> The following piece of code does not add the second parameter successfully and thus the
test fails.
> With a Member entity that has a place and a name field:
> {code:java}
>        Member m = new Member(1, "dave");
>         m.setAge(5);
>         m.setPlace("capetown");
>         em.persist(m);
>         CriteriaBuilder cb = em.getCriteriaBuilder();
>         CriteriaQuery<Member> q = cb.createQuery(Member.class);
>         Root<Member> c = q.from(Member.class);
>         ParameterExpression<String> name = cb.parameter(String.class);
>         ParameterExpression<String> place = cb.parameter(String.class);
>         CriteriaQuery<Member> where ="name"),
name), cb.equal(c.get("place"), place));
>         TypedQuery<Member> query = em.createQuery(where);
>         query.setParameter(name, "dave");
>         query.setParameter(place, "capetown");
>         List<Member> results = query.getResultList();
>         assertThat(results).isNotEmpty();
> {code}
> With query and parameter logging on you that the the sql call is made with the same parameter
> {noformat}
> <t 346847161, conn 1824423245> executing prepstmnt 2078396010 SELECT, t0.age,, FROM Member t0 WHERE ( = ? AND = ?) [params=(String) dave,
(String) dave]
> {noformat}
> And this kinda makes sense as this is what the CriteriaQueryImpl.registerParameter looks
> {code:java}
>     /**
>      * Registers the given parameter.
>      */
>     void registerParameter(ParameterExpressionImpl<?> p) {
>         for (Object k : _params.keySet()) {
>             if (p.paramEquals(k)) {
>                 // If a named ParameterExpressin did already get registered
>                 // with that exact name, then we do ignore it.
>                 // If we do a query.setParameter("someParamName", Bla)
>                 // then it must uniquely identify a Parameter.
>                 return;
>             }
>         }
>         p.setIndex(_params.size());
>         _params.put(p, p.getJavaType());
>     }
> {code}
> And [paramEquals|]
will not differentiate between two anonymous parameters.
> So I suspect we are going to need some mechanism for differentiating between two anonymous
parameters - and if we did this then I suspect the issue that caused this in the first place
might also be resolved. Possibly add some kind of counter or something that can give identity
to anonymous parameters.
>  Added test to []

This message was sent by Atlassian JIRA

View raw message