DataNucleus JIRA is now in read-only mode. Raise any new issues in GitHub against the plugin that it applies to. DataNucleus JIRA will remain for the foreseeable future but will eventually be discontinued
Issue Details (XML | Word | Printable)

Key: NUCRDBMS-535
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Andy Jefferson
Reporter: Christian Ernst
Votes: 0
Watchers: 0
Operations

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

java.lang.NullPointerException in getObjectById when Object has an Array field which is null and a fetchgroup is used

Created: 21/Jun/11 04:01 PM   Updated: 01/Aug/11 05:13 PM   Resolved: 21/Jun/11 08:34 PM
Component/s: None
Affects Version/s: 3.0.0.m5
Fix Version/s: 3.0.0.m6

File Attachments: 1. Zip Archive NullPointerExceptionFetchgroup.zip (7 kB)

Environment:
Windows XP 64 bit,
JDK 1.6.24,
MySQL 5.5.13

Datastore: MySQL


 Description  « Hide
A java.lang.NullPointerException in getObjectById when Object has an Array field which is null and a fetchgroup is used.

---------------
public class A {

private A[] array;

public A[] getArray() {
return array;
}

public void setArray(A[] array) {
this.array = array;
}
}
---------------
<jdo>
  <package name="org.datanucleus.test">
   <class name="A">
<inheritance strategy="new-table">
         <discriminator strategy="class-name">
         <column name="TYPE"/>
         </discriminator>
            </inheritance>
     <fetch-group name="array">
     <field name="array" recursion-depth="10"/>
     </fetch-group>
            <field name="array" embedded="true">
     <array element-type="A"/>
            </field>
        </class>
  </package>
</jdo>
---------------
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("datanucleus.properties");

        PersistenceManager pm = pmf.getPersistenceManager();
        Transaction tx = pm.currentTransaction();
        Object oid = null;
        try
        {
            tx.begin();
            A a = new A();
     pm.makePersistent(a);
     oid = pm.getObjectId(a);
            tx.commit();
        }
        catch (Exception e)
        {
            NucleusLogger.GENERAL.info(">> Exception thrown persisting objects", e);
        }
        finally
        {
            if (tx.isActive())
            {
                tx.rollback();
            }
        }

        pm.close();
        pmf.close();
        pmf = JDOHelper.getPersistenceManagerFactory("datanucleus.properties");
        pm = pmf.getPersistenceManager();
pm.getFetchPlan().addGroup("array");
pm.getFetchPlan().setMaxFetchDepth(-1);
        tx = pm.currentTransaction();
        try
        {
            tx.begin();
            
            // this gives a NPE
            A aa = (A) pm.getObjectById(oid);
    
            tx.commit();
        }
        catch (Exception e)
        {
             NucleusLogger.GENERAL.info(">> Exception thrown retrieving objects", e);
        }
        finally
        {
            if (tx.isActive())
            {
                tx.rollback();
            }
        }
        pm.close();
---------------


Sort Order: Ascending order - Click to sort in descending order
Christian Ernst added a comment - 21/Jun/11 04:02 PM
testcase

Christian Ernst added a comment - 21/Jun/11 04:56 PM
java.lang.NullPointerException
at org.datanucleus.store.rdbms.scostore.RDBMSFKArrayStore.getSQLStatementForIterator(RDBMSFKArrayStore.java:182)
at org.datanucleus.store.rdbms.scostore.RDBMSFKArrayStore.iterator(RDBMSFKArrayStore.java:90)
at org.datanucleus.store.mapped.scostore.AbstractArrayStore.getArray(AbstractArrayStore.java:61)
at org.datanucleus.store.mapped.mapping.ArrayMapping.postFetch(ArrayMapping.java:141)
at org.datanucleus.store.rdbms.request.FetchRequest.execute(FetchRequest.java:402)
at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.fetchObject(RDBMSPersistenceHandler.java:313)
at org.datanucleus.state.JDOStateManagerImpl.loadFieldsFromDatastore(JDOStateManagerImpl.java:1696)
at org.datanucleus.state.JDOStateManagerImpl.validate(JDOStateManagerImpl.java:3520)
at org.datanucleus.ObjectManagerImpl.findObject(ObjectManagerImpl.java:3027)
at org.datanucleus.api.jdo.JDOPersistenceManager.getObjectById(JDOPersistenceManager.java:1727)
at org.datanucleus.api.jdo.JDOPersistenceManager.getObjectById(JDOPersistenceManager.java:1708)
at org.datanucleus.test.Main.main(Main.java:51)

Andy Jefferson added a comment - 21/Jun/11 08:34 PM
Fix copy-paste typo