[ https://issues.apache.org/jira/browse/OPENJPA-2735?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16452422#comment-16452422 ]
Pawel Veselov commented on OPENJPA-2735: ---------------------------------------- This is what I ended up doing to "fix" this: {noformat} Index: src/main/java/org/apache/openjpa/jdbc/kernel/exps/InSubQExpression.java =================================================================== --- src/main/java/org/apache/openjpa/jdbc/kernel/exps/InSubQExpression.java (revision 1828187) +++ src/main/java/org/apache/openjpa/jdbc/kernel/exps/InSubQExpression.java (working copy) @@ -72,7 +72,17 @@ 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); + int l = _val.length(sel, ctx, istate.valueState); + if (l > 1) { + buf.append("("); + } + for (int i=0; i<l; i++) { + if (i>0) { buf.append(","); } + _val.appendTo(sel, ctx, istate.valueState, buf, i); + } + if (l>1) { + buf.append(")"); + } buf.append(" IN "); _sub.appendTo(sel, ctx, istate.valueState, buf, 0); } {noformat} > 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 > Priority: Major > > 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)