[ https://issues.apache.org/jira/browse/OPENJPA-1719?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12892128#action_12892128 ]
Catalina Wei commented on OPENJPA-1719: --------------------------------------- Some debugging work validates that in what order the parameters are added to _userIndex does not matter, because the positions of the parameters in _userIndex are corrected by look up the Param object in _userParams. The current code block in SQLBuffer.java (lines 169++): (1) if (buf._userIndex != null) { if (_userIndex == null) { _userIndex = new ArrayList(); _userIndex.addAll(buf._userIndex); } else _userIndex.addAll(paramIndex*2, buf._userIndex); // Wrong index leads to exception } Can be simplified to (2) if (buf._userIndex != null) { if (_userIndex == null) _userIndex = new ArrayList(); _userIndex.addAll(buf._userIndex); } There should be no IndexOutOfBoundException in (1). but (2) is more simplified code. > Prepared SQL cache ordering problem with subqueries. > ----------------------------------------------------- > > Key: OPENJPA-1719 > URL: https://issues.apache.org/jira/browse/OPENJPA-1719 > Project: OpenJPA > Issue Type: Bug > Affects Versions: 2.0.0 > Reporter: Michael Dick > Assignee: Catalina Wei > Fix For: 2.0.1, 2.1.0 > > Attachments: sql-cache-subqordering.diff.txt > > > I've found what appears to be an ordering issue with subqueries and the > prepared SQL cache. The attached patch shows where I think the problem lies > and adds a test method that shows the problem. > To summarize: When the prepared SQL cache is enabled we reorder the parameter > values provided by the user. If a query contains named parameters and a > subquery which also contains named parameters the placement of the subquery > becomes important. > The following query will work : > SELECT p FROM Person p WHERE p.id IN (SELECT p1.id FROM Person p1 WHERE > p1.lastUpdated >= :date ) AND p.name = :name > But this one fails with a SQLDataException. > SELECT p FROM Person p WHERE p.name = :name AND p.id IN (SELECT p1.id FROM > Person p1 WHERE p1.lastUpdated >= :date ) > Assuming that the query is executed something like this : > Query query = em.createQuery(query); > query.setParameter("name", "mike"); > query.setParameter("date", new java.sql.Date(1005397)); -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.