Pawel Veselov created OPENJPA-2735:
--------------------------------------
Summary: IN with sub-query doesn't work with compound IDs
Key: OPENJPA-2735
URL: https://issues.apache.org/jira/browse/OPENJPA-2735
Project: OpenJPA
Issue Type: Bug
Components: jdbc
Affects Versions: 2.4.2
Reporter: Pawel Veselov
Ran into this problem now.
With two entities, A and B, where A has multi-field ID (say id1 and id2), and B
has a field that references A. Running this query:
select b from B b where b.ref in ( select a from A ); causes problems.
I don't know how to create a test case for it, because this outright doesn't
work with Derby - derby doesn't allow for sub-queries that return more than one
field.
With postgres, this fails, because the query translates into:
{code:sql}
select * from b where b.ref_id1 in ( select a.id1, a.id2 from a );
{code}
The problem is in InSubQExpression.appendTo() method:
{code:java}
public void appendTo(Select sel, ExpContext ctx, ExpState state,
SQLBuffer buf) {
InSubQExpState istate = (InSubQExpState) state;
_sub.calculateValue(sel, ctx, istate.subqState, null, null);
_val.calculateValue(sel, ctx, istate.valueState, null, null);
_val.appendTo(sel, ctx, istate.valueState, buf, 0);
buf.append(" IN ");
_sub.appendTo(sel, ctx, istate.valueState, buf, 0);
}
{code}
The _val.appendTo() is called with index of 0, but that can be a compound
object (which it is in this case). I'm gonna try replacing the appendTo() call
with appendType(). I don't understand enough of this to know what I'm doing
though.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)