openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pawel Veselov <pawel.vese...@gmail.com>
Subject Re: Repeating parameter name causes all kinds of problems?
Date Sun, 01 Apr 2018 23:03:55 GMT
On Sun, Apr 1, 2018 at 2:51 PM, Pawel Veselov <pawel.veselov@gmail.com> wrote:
> Hello.
>
> I can't find much references to problems like this, which is
> surprising. May be I'm doing something that is prohibited by the spec?

The spec OKs to use the same parameter more than once (4.6.4.2 of 2.0)

> I want to re-use the same parameter twice. However, I'm seeing all
> kinds of behavior except for the one I want. This is with OpenJPA
> 2.4.2.

This seems to be broken in OpenJPA though. Especially if sub-queries
are involved. I traced this as much as I could, but I don't understand
the intend of the code. There are a few parameter representations.
org.apache.openjpa.jdbc.kernel.exps.Param, that has an "_idx" field,
defining which parameter value is actually going to be used. There is
a ParameterExpressionImpl that is constructed during query evaluation,
that has the "_index" field that is later used to populate the
Param._idx. While stepping through things I can see:

Considering query Select t1 from t1 t1 where t1.id in ( select t2.ref
from t2 t2 where t2.hash = :hash_value and t2.group = :tenancy) and
t1.group = :tenancy

I see:
1) ParameterExpressionImpl for tenancy is assigned _index 0
2) ParameterExpressionImpl for hash_value is assigned _index 1
3) Param for hash_value (sub-query) is assigned _idx 1
4) ParameterExpressionImpl for hash_value is re-assigned to index 0
(because now it's being processed within sub-query, and index is
assigned based on the current size of the parameters in the
CriteriaQueryImpl object)
5) ParameterExpressionImpl for tenancy is reassigned to index 1
6) Param for tenancy (sub-query) is assigned _idx 1 (because of step #5)
7) Param for tenancy (outer query) is assigned _idx 1 (because of step #5)

Param instances are one per parameter placement.
ParameterExpressionImpl instances are one per parameter

I wonder if the fix is just to copy the parameters into the sub-query
object when it's created. Then the parameters would be found, and
there indices not modified.

It also seems that if I use cb.parameter() twice, the second parameter
is not considered the same, even if the name is the same. I think
that's also a bug.

[skipped]


-- 
With best of best regards
Pawel S. Veselov

Mime
View raw message