datanucleus / datanucleus-api-jdo

Support for DataNucleus persistence using the JDO API (JSR0012, JSR0243)
18 stars 27 forks source link

JDOQLTypedQuery: wrong query result when replacing QFullTimeEmployee.candidate() by QFullTimeEmployee.candidate("this") #133

Open mboapache opened 2 weeks ago

mboapache commented 2 weeks ago

JDO TCK Class SampleReadQueries implements the sample queries from the JDO specification chapter 14.11.

Methods testQuery15f and testQuery16f implement the typesafe query version. The code uses QFullTimeEmployee.candidate() to access instances of the candidate class. The query returns a wrong query result, When replacing the call QFullTimeEmployee.candidate() by QFullTimeEmployee.candidate("this") The expected query result consist of three FullTimeEmployee instances wrapped into a EmpWrapper instance (testQuery15f) or EmpInfo instance (testQuery16f). Instead the FullTimeEmployee instance is null that gets wrappe into a EmpWrapper/EmpInfo.

The generated SQL does not differ depending on which candidate method is used.

To reprocude the issue please checkout branch JDO-843 of the Apache JDO repository https://github.com/apache/db-jdo/tree/JDO-843. The branch includes the test class JDO843Test that just has the failing methods testQuery15f and testQuery16f. Please run the following command: mvn -Djdo.tck.cfglist=JDO843.conf clean install You find the results in the directory tck/target/logs/ files app-JDO843-junit.txt or dsid-JDO843-junit.txt.

Junit Test results when running the test methods with QFullTimeEmployee.candidate("this"):

{{ JUnit Jupiter:JDO843Test:testQuery15f()}} {{ MethodSource [className = 'org.apache.jdo.tck.query.api.JDO843Test', methodName = 'testQuery15f', methodParameterTypes = '']}} {{ => org.opentest4j.AssertionFailedError: Assertion (SampleQueries) failed: }} {{Wrong query result: }} {{query: select into org.apache.jdo.tck.query.api.SampleReadQueries$EmpWrapper from org.apache.jdo.tck.pc.company.FullTimeEmployee where salary > :sal}} {{expected: java.util.ArrayList of size 3}} [EmpWrapper(FullTimeEmployee:name = Michael), EmpWrapper(FullTimeEmployee:name = Craig), EmpWrapper(FullTimeEmployee:name = Tillmann)] {{got: java.util.ArrayList of size 3}} [EmpWrapper(FullTimeEmployee:null), EmpWrapper(FullTimeEmployee:null), EmpWrapper(FullTimeEmployee:null)]

{{ JUnit Jupiter:JDO843Test:testQuery16f()}} {{ MethodSource [className = 'org.apache.jdo.tck.query.api.JDO843Test', methodName = 'testQuery16f', methodParameterTypes = '']}} {{ => org.opentest4j.AssertionFailedError: Assertion (SampleQueries) failed: }} {{Wrong query result: }} {{query: select into org.apache.jdo.tck.query.api.SampleReadQueries$EmpInfo from org.apache.jdo.tck.pc.company.FullTimeEmployee where salary > :sal}} {{expected: java.util.ArrayList of size 3}} [EmpInfo(worker:Michael), EmpInfo(worker:Craig), EmpInfo(worker:Tillmann)] {{got: java.util.ArrayList of size 3}} [EmpInfo(worker:null), EmpInfo(worker:null), EmpInfo(worker:null)]

mboapache commented 1 week ago

Please note, there is a new checkin in branch JDO-843. With this checkin there are diffrent testcases for success (testQuery15fSuccess / testQuery16fSuccess) and failure (testQuery15fFailure / testQuery16fFailure).

Please also note, I put the JUnit @Test annotation in comments for the two success methods. When running the success methods together with the failure methods all 4 methods return the expected result. When running the failure mthods w/o the success methods the two failure methods return the unexpected result.

andyjefferson commented 1 day ago

For DataNucleus the "typesafe" interface simply provide a mechanism for creating the "generic compilation" that equates to what is created for string-based JDOQL; such things are printed in the log at DEBUG level. Suggest you inspect the log for what is created.