Issue Details (XML | Word | Printable)

Key: NUCRDBMS-816
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Florian Schmitt
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
DataNucleus Store RDBMS

Incorrect handling of join expressions when using multiple joins

Created: 30/Jul/14 12:09 PM   Updated: 10/Aug/14 12:57 PM   Resolved: 30/Jul/14 03:01 PM
Component/s: Queries
Affects Version/s: 4.0.1
Fix Version/s: 4.0.2

File Attachments: 1. Text File 0001-data-nucleus-version-4.0.1.patch (2 kB)
2. Text File 0001-fixed-problem-with-join-expression-not-using-the-cor.patch (1 kB)
3. Text File 0002-added-test-case-for-multiple-joins-finishing-at-the-.patch (2 kB)

Environment: Windows 64 bit, Java 8, JPA

Severity: Production


 Description  « Hide
There is a problem when using multiple join expressions. It occurs when using a query like "Select d From Department d Join d.projects p Join d.manager m". The bug takes place, while traversing the join expressions. When the first join is evaluated, the ClassMetadata from the joined Entity (in this case Project) is loaded. When evaluating the next join expression, the ClassMetadata is not updated, thus it is tried to access a field with name manager of class Project (instead of the correct class Department), resulting in an PersistenceException: Query has d.manager yet manager is not found. Fix your input
        at org.datanucleus.store.rdbms.query.QueryToSQLMapper.compileFromClassExpression(QueryToSQLMapper.java:1263)

I extended the DataNucleus test suite with this simple query and I implemented a quick fix. I only use JPA, I cannot tell whether this occurs with JDO also.

Florian Schmitt added a comment - 30/Jul/14 12:10 PM
test suite set to version 4.0.1 and added the test case

Florian Schmitt made changes - 30/Jul/14 12:10 PM
Field Original Value New Value
Attachment 0001-data-nucleus-version-4.0.1.patch [ 12070 ]
Attachment 0002-added-test-case-for-multiple-joins-finishing-at-the-.patch [ 12071 ]
Florian Schmitt added a comment - 30/Jul/14 12:10 PM
added a quick fix for this bug

Florian Schmitt made changes - 30/Jul/14 12:10 PM
Florian Schmitt added a comment - 30/Jul/14 12:31 PM
Sorry, i forgot some copy/paste leftover in the finally block at the end of the testcase

Andy Jefferson added a comment - 30/Jul/14 03:01 PM
Patch applied to GitHub, thx. But note that there is a TODO in the code there to complete that logic.

PS, whilst I said raise an issue in JIRA for registering problems (which is the way), that doesn't mean that you can't provide contributed source updates via GitHub pull requests ... just mention the pull request in the JIRA issue, so saves you creating patch files and attaching them here etc. The only thing I want to avoid is having pull requests being raised but no accompanying JIRA issue. Hope that's clearer:-)

Andy Jefferson made changes - 30/Jul/14 03:01 PM
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 4.0.2 [ 12235 ]
Resolution Fixed [ 1 ]
Andy Jefferson made changes - 10/Aug/14 12:57 PM
Status Resolved [ 5 ] Closed [ 6 ]