openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sandeep Shrivastava (JIRA)" <>
Subject [jira] Created: (OPENJPA-562) NPE when trying to invoke FieldMetada.getOrders() when a PersistenCollection field is being loaded.
Date Tue, 08 Apr 2008 21:37:24 GMT
NPE when trying to invoke FieldMetada.getOrders() when a PersistenCollection field is being

                 Key: OPENJPA-562
             Project: OpenJPA
          Issue Type: Bug
          Components: kernel
    Affects Versions: 1.1.0
         Environment: This error occured on Microsoft Windows XP SP2, Java version = 1.6.0
with mySQL 5.0 Database.
            Reporter: Sandeep Shrivastava
             Fix For: 1.1.0

Consider the following snippet of an entity definition:

 * <p>Entity used to test parsing of @OrderBy.</p>
 * @author Abe White
public class OrderByEntity {

    private long id;
    private String string;

    private List<String> strings = new ArrayList();


The @PersistentCollection annotation maps the declaration to the default collection table
named orderbyentity_strings. The join column name in the container table is also defaulted
to orderbyentity_id and the name of the Element column name is defaulted to element. 

The test code initially added string elements to the strings list and persisted it.

        OrderByEntity pc = new OrderByEntity();

On a subsequent load of the persistent collection data by executing the following code, we
hit into an NPE.

        pc = em.find(OrderByEntity.class, 1L);
        List<String> strings = pc.getStrings();

at org.apache.openjpa.meta.FieldMetaData.getOrders(
at org.apache.openjpa.jdbc.meta.strats.StoreCollectionFieldStrategy.selectEager(
at org.apache.openjpa.jdbc.meta.strats.StoreCollectionFieldStrategy.selectEagerJoin(
at org.apache.openjpa.jdbc.meta.FieldMapping.selectEagerJoin(
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(
at org.apache.openjpa.kernel.DelegatingStoreManager.load(
at org.apache.openjpa.datacache.DataCacheStoreManager.load(
at org.apache.openjpa.kernel.DelegatingStoreManager.load(
at org.apache.openjpa.kernel.ROPStoreManager.load(
at org.apache.openjpa.kernel.StateManagerImpl.loadFields(
at org.apache.openjpa.kernel.StateManagerImpl.loadField(
at kodo.kernel.ProfilingStateManager.loadField(
at org.apache.openjpa.kernel.StateManagerImpl.beforeAccessField(
at kodo.kernel.ProfilingStateManager.beforeAccessField(
at org.apache.openjpa.kernel.StateManagerImpl.accessingField(

This problem is reported with OpenJPA version:

$ java org.apache.openjpa.conf.OpenJPAVersion
version id: openjpa-1.1.0-SNAPSHOT-r420667:634150
Apache svn revision: 420667:634150 Windows XP
os.version: 5.1
os.arch: x86

java.version: 1.6.0_05
java.vendor: BEA Systems, Inc.

The NPE occurs when the FieldMetadata.getOrders() method is invoked when trying to load the
data in the strings collection field. The code is trying to get the ClassMetadata for the
element type and then check the FieldMetadata is present in the declared fields. It fails
because the element data type is java.lang.String and there is no ClassMetadata for it. By
simply adding a null check for the returned class metadata this issue I could fix locally.

Here is the outout of the svn diff command.

C:\apache_openjpa_project\openjpa>svn diff
Index: openjpa-kernel/src/main/java/org/apache/openjpa/meta/
--- openjpa-kernel/src/main/java/org/apache/openjpa/meta/
(revision 643944)
+++ openjpa-kernel/src/main/java/org/apache/openjpa/meta/
(working copy)
@@ -1124,9 +1124,11 @@
                     //set "isUsedInOrderBy" to the field
                     ClassMetaData elemCls = getElement()
-                    FieldMetaData fmd = elemCls.getDeclaredField(decs[i]);
-                    if (fmd != null)
-                       fmd.setUsedInOrderBy(true);
+                    if (elemCls != null) {
+                      FieldMetaData fmd = elemCls.getDeclaredField(decs[i]);
+                      if (fmd != null)
+                        fmd.setUsedInOrderBy(true);
+                    }
                 _orders = orders;

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message