OpenJPA
  1. OpenJPA
  2. OPENJPA-2144

Using recursive relationships along with Identity Class leads to NullPointerException

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.2, 2.0.0, 2.0.1, 2.1.0, 2.1.1, 2.2.0
    • Fix Version/s: None
    • Component/s: jdbc
    • Labels:
      None
    • Patch Info:
      Patch Available

      Description

      Partially defined entity:

      @Entity
      @IdClass(Node2.ID.class)
      public class Node2 {
      @Id
      @GeneratedValue
      private long id;
      @Id private int region = 1;
      @Id private int district = 2;

      @ManyToOne(fetch = LAZY)
      @JoinColumns(

      { @JoinColumn(name = "PARENT_ID", referencedColumnName = "ID"), @JoinColumn(name = "REGION", referencedColumnName = "REGION"), @JoinColumn(name = "DISTRICT", referencedColumnName = "DISTRICT") }

      )
      private Node2 parent;

      @OneToMany(mappedBy = "parent", cascade = ALL, fetch = LAZY)
      private List<Node2> nodes = new ArrayList<Node2>();

      // getters, setters, etc.
      // full text will be attached as a unit test: TestRecursiveRelationshipsWithIdClass.testTree()

      An attempt to use a such entity leads to NullPointerException :

      FailedObject: org.apache.openjpa.persistence.recursive.idclass.Node2-1151::1::2 [java.lang.String]
      at org.apache.openjpa.kernel.BrokerImpl.refreshInternal(BrokerImpl.java:3107)
      at org.apache.openjpa.kernel.BrokerImpl.refresh(BrokerImpl.java:2998)
      at org.apache.openjpa.kernel.DelegatingBroker.refresh(DelegatingBroker.java:1134)
      at org.apache.openjpa.persistence.EntityManagerImpl.refresh(EntityManagerImpl.java:780)
      at org.apache.openjpa.persistence.EntityManagerImpl.refresh(EntityManagerImpl.java:757)
      at org.apache.openjpa.persistence.recursive.idclass.TestRecursiveRelationshipsWithIdClass.setUpInitialTree(TestRecursiveRelationshipsWithIdClass.java:130)
      at org.apache.openjpa.persistence.recursive.idclass.TestRecursiveRelationshipsWithIdClass.testPreparedSQLQueryToTree(TestRecursiveRelationshipsWithIdClass.java:92)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:600)
      at junit.framework.TestCase.runTest(TestCase.java:154)
      at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.runTest(AbstractPersistenceTestCase.java:579)
      at junit.framework.TestCase.runBare(TestCase.java:127)
      at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.runBare(AbstractPersistenceTestCase.java:566)
      at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.runBare(AbstractPersistenceTestCase.java:542)
      at junit.framework.TestResult$1.protect(TestResult.java:106)
      at junit.framework.TestResult.runProtected(TestResult.java:124)
      at junit.framework.TestResult.run(TestResult.java:109)
      at junit.framework.TestCase.run(TestCase.java:118)
      at org.apache.openjpa.persistence.test.AbstractPersistenceTestCase.run(AbstractPersistenceTestCase.java:206)
      at junit.framework.TestSuite.runTest(TestSuite.java:208)
      at junit.framework.TestSuite.run(TestSuite.java:203)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:600)
      at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
      at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:115)
      at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:102)
      at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:600)
      at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
      at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
      Caused by: java.lang.NullPointerException
      at org.apache.openjpa.util.ApplicationIds$PrimaryKeyFieldManager.fetchLongField(ApplicationIds.java:669)
      at org.apache.openjpa.persistence.recursive.idclass.Node2.pcCopyKeyFieldsToObjectId(Node2.java)
      at org.apache.openjpa.enhance.PCRegistry.copyKeyFieldsToObjectId(PCRegistry.java:171)
      at org.apache.openjpa.util.ApplicationIds.fromPKValues(ApplicationIds.java:224)
      at org.apache.openjpa.jdbc.meta.ClassMapping.getObjectId(ClassMapping.java:223)
      at org.apache.openjpa.jdbc.meta.ClassMapping.getObjectId(ClassMapping.java:147)
      at org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.load(RelationFieldStrategy.java:736)
      at org.apache.openjpa.jdbc.meta.FieldMapping.load(FieldMapping.java:928)
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:1094)
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:1038)
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:659)
      at org.apache.openjpa.util.ImplHelper.loadAll(ImplHelper.java:107)
      at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.loadAll(JDBCStoreManager.java:695)
      at org.apache.openjpa.kernel.DelegatingStoreManager.loadAll(DelegatingStoreManager.java:122)
      at org.apache.openjpa.kernel.BrokerImpl.refreshInternal(BrokerImpl.java:3071)
      ... 36 more

      1. TestRecursiveRelationshipsWithIdClass.jar
        5 kB
        Dmitry Pavlov
      2. openjpa-2144-trunk.patch
        1 kB
        Dmitry Pavlov

        Issue Links

          Activity

          Hide
          Dmitry Pavlov added a comment - - edited

          Node2.java - full implementation of an entity class shown in the issue description.
          TestRecursiveRelationshipsWithIdClass.java - unit test for the issue.

          Provided unit test demonstrates the issue ( see testTree() ).
          It also shows query problems while using "Identity Class"
          (see testPreparedSQLQueryToTree(), see OPENJPA-2147).

          Show
          Dmitry Pavlov added a comment - - edited Node2.java - full implementation of an entity class shown in the issue description. TestRecursiveRelationshipsWithIdClass.java - unit test for the issue. Provided unit test demonstrates the issue ( see testTree() ). It also shows query problems while using "Identity Class" (see testPreparedSQLQueryToTree(), see OPENJPA-2147 ).
          Hide
          Dmitry Pavlov added a comment - - edited

          I was able to fix this issue just to downgrade org.apache.openjpa.jdbc.meta.ClassMapping.getObjectId(...) function as it had been in 1.2.1 version.

          Show
          Dmitry Pavlov added a comment - - edited I was able to fix this issue just to downgrade org.apache.openjpa.jdbc.meta.ClassMapping.getObjectId(...) function as it had been in 1.2.1 version.

            People

            • Assignee:
              Unassigned
              Reporter:
              Dmitry Pavlov
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:

                Development