Issue Details (XML | Word | Printable)

Key: NUCRDBMS-749
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Julian Schillinger
Votes: 0
Watchers: 0
Operations

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

Select of identity field(s) on candidate with new-table inheritance and PK in superclass/table can cause error in SQL generation

Created: 10/Jan/14 07:24 AM   Updated: 11/Jan/14 07:43 PM   Resolved: 10/Jan/14 01:09 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 3.2.11

File Attachments: 1. Zip Archive 20130110_DNFetchGroupsTestCase_InconsitentTable.zip (7 kB)
2. Java Source File SQLStatement-FIXED1.java (81 kB)

Environment: 64bit ubuntu, OpenJDK 7

Datastore: MySQL
Severity: Production


 Description  « Hide
*** Overview:
I have an abstract class 'Parent', which is extended by class 'ParentMale'. 'Parent' has a list-field called 'children' which contains 'Child' elements and is in the fetch group. If one queries for 'Parent' elements no error occurs. If one queries on 'ParentMale' elements, this error occurs: org.datanucleus.exceptions.NucleusException: Table being selected from ("`PARENTMALE`") is inconsistent with the column selected ("`PARENT`"). Will attach testcase. Taking children out of the fetch group will result in no error. This is related to the 'new' bulk-fetching of SCO objects.


*** Stacktrace Table being selected from ("`PARENTMALE`") is inconsistent with the column selected ("`PARENT`")
javax.jdo.JDOException: Table being selected from ("`PARENTMALE`") is inconsistent with the column selected ("`PARENT`")
at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:600)
at org.datanucleus.api.jdo.JDOQuery.compile(JDOQuery.java:99)
at org.datanucleus.test.Main2.main(Main2.java:91)
NestedThrowablesStackTrace:
Table being selected from ("`PARENTMALE`") is inconsistent with the column selected ("`PARENT`")
org.datanucleus.exceptions.NucleusException: Table being selected from ("`PARENTMALE`") is inconsistent with the column selected ("`PARENT`")
at org.datanucleus.store.rdbms.sql.SQLStatement.select(SQLStatement.java:495)
at org.datanucleus.store.rdbms.sql.SQLStatementHelper.selectIdentityOfCandidateInStatement(SQLStatementHelper.java:471)
at org.datanucleus.store.rdbms.query.QueryToSQLMapper.compileResult(QueryToSQLMapper.java:793)
at org.datanucleus.store.rdbms.query.QueryToSQLMapper.compile(QueryToSQLMapper.java:402)
at org.datanucleus.store.rdbms.query.BulkFetchHelper.getSQLStatementForContainerField(BulkFetchHelper.java:144)
at org.datanucleus.store.rdbms.query.JDOQLQuery.compileQueryFull(JDOQLQuery.java:1067)
at org.datanucleus.store.rdbms.query.JDOQLQuery.compileInternal(JDOQLQuery.java:363)
at org.datanucleus.store.query.Query.compile(Query.java:1609)
at org.datanucleus.api.jdo.JDOQuery.compile(JDOQuery.java:95)
at org.datanucleus.test.Main2.main(Main2.java:91)


*** Relevant code piece

// set up fetch group
pm1.getFetchPlan().addGroup("fetchgrp1"); // adding this line causes the exception

// getting parent object
NucleusLogger.GENERAL.info("Getting parent object with key "
+ keyToLookFor);
Query query = pm1.newQuery(ParentMale.class); // causes error
// Query query = pm1.newQuery(Parent.class); // does not causes error

query.setFilter("key == my_key");
query.declareParameters("String my_key");
query.compile(); // this is where the error occurs
List<Parent> parents = (List<Parent>) query.execute(keyToLookFor);


*** Libs
datanucleus-api-jdo-3.2.7.jar
datanucleus-core-3.2.11.jar
datanucleus-rdbms-3.2.10.jar
datanucleus-cache-3.1.3.jar





Sort Order: Ascending order - Click to sort in descending order
Julian Schillinger added a comment - 10/Jan/14 07:40 AM - edited
Hi Andy,

Seems like the error check below in SQLStatement.select(...) does not take inheritance into account when querying for the extending class. Removing it makes attached test case pass.

 public int[] select(SQLTable table, JavaTypeMapping mapping, String alias, boolean applyToUnions)
    {

        ...
        
        // removing below fixes/works around NUCRDBMS-749
        /*if (mapping.getTable() != table.getTable())
        {
            throw new NucleusException("Table being selected from (\"" + table.getTable() +
                "\") is inconsistent with the column selected (\"" + mapping.getTable() + "\")");
        }*/

        ...

I attached fixed JAR file and SQLStatement.java.

Julian

Andy Jefferson added a comment - 10/Jan/14 01:09 PM
GitHub master fixes select of identity field(s) using the SQLStatement query mechanism. It does not use the proposed fix since a sanity check for correct input is there for a reason, and signifies that some upstream call is passing in invalid input; this is fixes in SQLStatementHelper and ClassTable. Note that this is nothing to do with bulk-fetch functionality and could have come up with any query using new-table inheritance and selecting just the identity field(s)