OpenJPA
  1. OpenJPA
  2. OPENJPA-560

merge() throws NPE or unable to create proxy

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.1.0
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      Linux 2.6, Java 1.5.0_12, Derby 10.3.2.1

      Description

      I have reduced this to a stand-alone unit test and also tested it against Toplink and Hibernate, with which it works.

      So I'm looking at a pure OpenJPA issue here.

      Here is the low-down:

      • Parent - child entities mapped using XML as opposed to annotations
      • both inherit a mapped superclass
      • both have a prepersist and preupdate listener configured
      • not using enhancement

      This is all I do:

      EntityManager entityManager =
      db.entityManagerFactory.createEntityManager();
      entityManager.getTransaction().begin();
      Genus genus = entityManager.find(Genus.class, new Long(1));
      entityManager.getTransaction().commit();
      entityManager.close();
      // now detached
      entityManager = db.entityManagerFactory.createEntityManager();
      entityManager.getTransaction().begin();
      entityManager.merge(genus);

      and it throws an exception. If there is a child row in the db, I get the exception below.

      If there is no child in existence, I get a NullPointerException.

      If I enhance the entities, all is hunkydory.

      This is using OpenJPA v1.1.0 snapshot from February.

      $Proxy13 seems to be the name of the parent's child collection property, I can see from debugging.

      <openjpa-1.1.0-SNAPSHOT-r420667:609825 fatal general error> org.apache.openjpa.persistence.PersistenceException: Unable to create a second class object proxy for final class "class $Proxy13".
      at org.apache.openjpa.util.ProxyManagerImpl.assertNotFinal(ProxyManagerImpl.java:555)
      at org.apache.openjpa.util.ProxyManagerImpl.generateProxyCollectionBytecode(ProxyManagerImpl.java:524)
      at org.apache.openjpa.util.ProxyManagerImpl.getFactoryProxyCollection(ProxyManagerImpl.java:373)
      at org.apache.openjpa.util.ProxyManagerImpl.copyCollection(ProxyManagerImpl.java:192)
      at org.apache.openjpa.kernel.AttachStrategy.copyCollection(AttachStrategy.java:342)
      at org.apache.openjpa.kernel.AttachStrategy.attachCollection(AttachStrategy.java:319)
      at org.apache.openjpa.kernel.AttachStrategy.replaceList(AttachStrategy.java:357)
      at org.apache.openjpa.kernel.AttachStrategy.attachField(AttachStrategy.java:222)
      at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:151)
      at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241)
      at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:101)
      at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3196)
      at org.apache.openjpa.kernel.DelegatingBroker.attach(DelegatingBroker.java:1142)
      at org.apache.openjpa.persistence.EntityManagerImpl.merge(EntityManagerImpl.java:736)
      at org.permacode.atomictest.jpa.JpaSpeciesDao.persist(JpaSpeciesDao.java:81)

        Activity

        Adam Hardy created issue -
        Hide
        Adam Hardy added a comment -

        In case you don't use maven, here are the dependencies (exc. stuff for Hibernate and Toplink):

        commons-collections:commons-collections:jar:3.2:compile
        [INFO] commons-lang:commons-lang:jar:2.1:compile
        [INFO] commons-logging:commons-logging:jar:1.0.4:compile
        [INFO] commons-pool:commons-pool:jar:1.3:compile
        [INFO] javax.persistence:persistence-api:jar:1.0:compile
        [INFO] javax.transaction:jta:jar:1.0.1B:compile
        [INFO] junit:junit:jar:4.1:compile
        [INFO] net.sourceforge.serp:serp:jar:1.13.1:compile
        [INFO] org.apache.derby:derby:jar:10.3.2.1:compile
        [INFO] org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.0.1:compile
        [INFO] org.apache.geronimo.specs:geronimo-jpa_3.0_spec:jar:1.0:compile
        [INFO] org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1:compile
        [INFO] org.apache.openjpa:openjpa:jar:1.1.0-SNAPSHOT:compile

        Show
        Adam Hardy added a comment - In case you don't use maven, here are the dependencies (exc. stuff for Hibernate and Toplink): commons-collections:commons-collections:jar:3.2:compile [INFO] commons-lang:commons-lang:jar:2.1:compile [INFO] commons-logging:commons-logging:jar:1.0.4:compile [INFO] commons-pool:commons-pool:jar:1.3:compile [INFO] javax.persistence:persistence-api:jar:1.0:compile [INFO] javax.transaction:jta:jar:1.0.1B:compile [INFO] junit:junit:jar:4.1:compile [INFO] net.sourceforge.serp:serp:jar:1.13.1:compile [INFO] org.apache.derby:derby:jar:10.3.2.1:compile [INFO] org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.0.1:compile [INFO] org.apache.geronimo.specs:geronimo-jpa_3.0_spec:jar:1.0:compile [INFO] org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1:compile [INFO] org.apache.openjpa:openjpa:jar:1.1.0-SNAPSHOT:compile
        Adam Hardy made changes -
        Field Original Value New Value
        Attachment bug-jpa-merge.zip [ 12379665 ]
        Hide
        gioni added a comment -

        I have encountered the some error with OpenJPA version 1.1.0, when i try to merge a detached entity.
        Environment: Swing app, openJPA 1.1.0, jdk1.6.0_06, Firebird 2.1, Windows 2000.

        With OpenJPA version 1.0.2 and TopLink works fine.

        -----------
        Exception in thread "AWT-EventQueue-0" java.lang.Error: java.lang.reflect.InvocationTargetException
        at org.jdesktop.application.ApplicationAction.actionFailed(ApplicationAction.java:859)
        at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:665)
        at org.jdesktop.application.ApplicationAction.actionPerformed(ApplicationAction.java:698)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
        at java.awt.Component.processMouseEvent(Component.java:6041)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
        at java.awt.Component.processEvent(Component.java:5806)
        at java.awt.Container.processEvent(Container.java:2058)
        at java.awt.Component.dispatchEventImpl(Component.java:4413)
        at java.awt.Container.dispatchEventImpl(Container.java:2116)
        at java.awt.Component.dispatchEvent(Component.java:4243)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
        at java.awt.Container.dispatchEventImpl(Container.java:2102)
        at java.awt.Window.dispatchEventImpl(Window.java:2440)
        at java.awt.Component.dispatchEvent(Component.java:4243)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
        Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:662)
        ... 27 more
        Caused by: <openjpa-1.1.0-r422266:657916 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: null
        at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3213)
        at org.apache.openjpa.kernel.DelegatingBroker.attach(DelegatingBroker.java:1158)
        at org.apache.openjpa.persistence.EntityManagerImpl.merge(EntityManagerImpl.java:769)
        at ro.mig.InvoiceView.saveInvoice(InvoiceView.java:597)
        at ro.mig.InvoiceView.save(InvoiceView.java:621)
        ... 32 more
        Caused by: java.lang.NullPointerException
        at org.apache.openjpa.kernel.StateManagerImpl.replaceObjectField(StateManagerImpl.java:2056)
        at org.apache.openjpa.enhance.ro$mig$entity$InvoiceHeader$pcsubclass.pcReplaceField(Unknown Source)
        at org.apache.openjpa.kernel.StateManagerImpl.replaceField(StateManagerImpl.java:3015)
        at org.apache.openjpa.kernel.StateManagerImpl.storeObjectField(StateManagerImpl.java:2453)
        at org.apache.openjpa.kernel.StateManagerImpl.storeObject(StateManagerImpl.java:2443)
        at org.apache.openjpa.jdbc.meta.strats.StoreCollectionFieldStrategy.load(StoreCollectionFieldStrategy.java:493)
        at org.apache.openjpa.jdbc.meta.FieldMapping.load(FieldMapping.java:802)
        at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:520)
        at org.apache.openjpa.kernel.DelegatingStoreManager.load(DelegatingStoreManager.java:116)
        at org.apache.openjpa.kernel.ROPStoreManager.load(ROPStoreManager.java:78)
        at org.apache.openjpa.kernel.StateManagerImpl.loadFields(StateManagerImpl.java:2911)
        at org.apache.openjpa.kernel.StateManagerImpl.loadField(StateManagerImpl.java:2989)
        at org.apache.openjpa.kernel.StateManagerImpl.fetchObjectField(StateManagerImpl.java:2238)
        at org.apache.openjpa.kernel.StateManagerImpl.fetchField(StateManagerImpl.java:775)
        at org.apache.openjpa.kernel.StateManagerImpl.fetch(StateManagerImpl.java:737)
        at org.apache.openjpa.enhance.RedefinitionHelper$1.invoke(RedefinitionHelper.java:230)
        at $Proxy14.isEmpty(Unknown Source)
        at org.apache.openjpa.kernel.AttachStrategy.attachField(AttachStrategy.java:213)
        at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:161)
        at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241)
        at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:101)
        at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3206)
        ... 36 more

        -----------

        Show
        gioni added a comment - I have encountered the some error with OpenJPA version 1.1.0, when i try to merge a detached entity. Environment: Swing app, openJPA 1.1.0, jdk1.6.0_06, Firebird 2.1, Windows 2000. With OpenJPA version 1.0.2 and TopLink works fine. ----------- Exception in thread "AWT-EventQueue-0" java.lang.Error: java.lang.reflect.InvocationTargetException at org.jdesktop.application.ApplicationAction.actionFailed(ApplicationAction.java:859) at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:665) at org.jdesktop.application.ApplicationAction.actionPerformed(ApplicationAction.java:698) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272) at java.awt.Component.processMouseEvent(Component.java:6041) at javax.swing.JComponent.processMouseEvent(JComponent.java:3265) at java.awt.Component.processEvent(Component.java:5806) at java.awt.Container.processEvent(Container.java:2058) at java.awt.Component.dispatchEventImpl(Component.java:4413) at java.awt.Container.dispatchEventImpl(Container.java:2116) at java.awt.Component.dispatchEvent(Component.java:4243) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916) at java.awt.Container.dispatchEventImpl(Container.java:2102) at java.awt.Window.dispatchEventImpl(Window.java:2440) at java.awt.Component.dispatchEvent(Component.java:4243) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) at java.awt.EventDispatchThread.run(EventDispatchThread.java:121) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:662) ... 27 more Caused by: <openjpa-1.1.0-r422266:657916 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: null at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3213) at org.apache.openjpa.kernel.DelegatingBroker.attach(DelegatingBroker.java:1158) at org.apache.openjpa.persistence.EntityManagerImpl.merge(EntityManagerImpl.java:769) at ro.mig.InvoiceView.saveInvoice(InvoiceView.java:597) at ro.mig.InvoiceView.save(InvoiceView.java:621) ... 32 more Caused by: java.lang.NullPointerException at org.apache.openjpa.kernel.StateManagerImpl.replaceObjectField(StateManagerImpl.java:2056) at org.apache.openjpa.enhance.ro$mig$entity$InvoiceHeader$pcsubclass.pcReplaceField(Unknown Source) at org.apache.openjpa.kernel.StateManagerImpl.replaceField(StateManagerImpl.java:3015) at org.apache.openjpa.kernel.StateManagerImpl.storeObjectField(StateManagerImpl.java:2453) at org.apache.openjpa.kernel.StateManagerImpl.storeObject(StateManagerImpl.java:2443) at org.apache.openjpa.jdbc.meta.strats.StoreCollectionFieldStrategy.load(StoreCollectionFieldStrategy.java:493) at org.apache.openjpa.jdbc.meta.FieldMapping.load(FieldMapping.java:802) at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:520) at org.apache.openjpa.kernel.DelegatingStoreManager.load(DelegatingStoreManager.java:116) at org.apache.openjpa.kernel.ROPStoreManager.load(ROPStoreManager.java:78) at org.apache.openjpa.kernel.StateManagerImpl.loadFields(StateManagerImpl.java:2911) at org.apache.openjpa.kernel.StateManagerImpl.loadField(StateManagerImpl.java:2989) at org.apache.openjpa.kernel.StateManagerImpl.fetchObjectField(StateManagerImpl.java:2238) at org.apache.openjpa.kernel.StateManagerImpl.fetchField(StateManagerImpl.java:775) at org.apache.openjpa.kernel.StateManagerImpl.fetch(StateManagerImpl.java:737) at org.apache.openjpa.enhance.RedefinitionHelper$1.invoke(RedefinitionHelper.java:230) at $Proxy14.isEmpty(Unknown Source) at org.apache.openjpa.kernel.AttachStrategy.attachField(AttachStrategy.java:213) at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:161) at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241) at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:101) at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3206) ... 36 more -----------
        Hide
        Michael Dick added a comment -

        This is probably a result of the changes made for OPENJPA-245. In the mean time enhancing the entities will resolve (or at least avoid) the problem.

        Show
        Michael Dick added a comment - This is probably a result of the changes made for OPENJPA-245 . In the mean time enhancing the entities will resolve (or at least avoid) the problem.

          People

          • Assignee:
            Unassigned
            Reporter:
            Adam Hardy
          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:

              Development