openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
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

     [ https://issues.apache.org/jira/browse/OPENJPA-2788?focusedWorklogId=232364&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-232364
]

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
URL: https://github.com/apache/openjpa/pull/42
 
 
   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:
users@infra.apache.org


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: https://issues.apache.org/jira/browse/OPENJPA-2788
>             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 = q.select(c).where(cb.equal(c.get("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
twice...
> {noformat}
> <t 346847161, conn 1824423245> executing prepstmnt 2078396010 SELECT t0.id, t0.age,
t0.name, t0.place FROM Member t0 WHERE (t0.name = ? AND t0.place = ?) [params=(String) dave,
(String) dave]
> {noformat}
> And this kinda makes sense as this is what the CriteriaQueryImpl.registerParameter looks
like:
> {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|https://github.com/apache/openjpa/blob/9f26ed29bf31b5c8ab68c5257d42e8c88765cf9b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ParameterExpressionImpl.java#L142]
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 [https://github.com/michaelwiles/openjpa-bugs]



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message