5 Replies Latest reply on Apr 2, 2009 11:28 AM by Adam Warski

    java.lang.NullPointerException on onPreRemoveCollection of A

    Francesco Di Salvatore Newbie

      Hi all,

      I get this exception when trying to replicate an object in a synchronized database:

      DEBUG [main] (CodeSystemDAOHibernate.java:131) - java.lang.NullPointerException
       at org.hibernate.envers.event.AuditEventListener.onPreRemoveCollection(AuditEventListener.java:235)
       at org.hibernate.action.CollectionRemoveAction.preRemove(CollectionRemoveAction.java:134)
       at org.hibernate.action.CollectionRemoveAction.execute(CollectionRemoveAction.java:100)
       at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:169)
       at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
       at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
       at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
       at com.phi.dictionarymanager.logic.hibernate.GenericDAOHibaernate.commitNetwork(GenericDAOHibaernate.java:183)
       at com.phi.dictionarymanager.logic.hibernate.CodeSystemDAOHibernate.save(CodeSystemDAOHibernate.java:92)
       at com.phi.dictionarymanager.ui.widgets.VocabolaryItemNewComposite.save(VocabolaryItemNewComposite.java:515)
       at com.phi.dictionarymanager.ui.widgets.VocabularyDomainsNavigatorComposite$18.handleEvent(VocabularyDomainsNavigatorComposite.java:1434)
       at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
       at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
       at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3682)
       at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3293)
       at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
       at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
       at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
       at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
       at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
       at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
       at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
       at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
       at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:169)
       at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
       at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
       at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
       at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:508)
       at org.eclipse.equinox.launcher.Main.basicRun(Main.java:447)
       at org.eclipse.equinox.launcher.Main.run(Main.java:1173)
       at org.eclipse.equinox.launcher.Main.main(Main.java:1148)
      


      Code throwing the exception:

      beginTransactionLocal();
      makePersistentLocal(cs);
      commitLocal();
      closeSessionLocal();
      
      beginTransactionNetwork();
      makePersistentNetwork(cs);
      commitNetwork();
      closeSessionNetwork();
      


      For this insertion of the object cs, the makePersistentLocal makes a saveOrUpdate call, while makePersistentNetwork calls replicate(cs, ReplicateMode.LATEST_VERSION).

      My hibernate-mysql.cfg.xml and hibernate-hsql.cfg.xml are very similar (I post only the mysql one):

      <hibernate-configuration>
       <session-factory>
       ...
       <property name="org.hibernate.envers.revisionOnCollectionChange">true</property>
       <property name="org.hibernate.envers.doNotAuditOptimisticLockingField">true</property>
      
      
       <!-- HIBERNATE BEAN MAPPINGS -->
       <mapping resource="com/phi/dictionarymanager/beans/CodeEquivalent.hbm.xml" />
       <mapping resource="com/phi/dictionarymanager/beans/CodeValue.hbm.xml" />
       <mapping resource="com/phi/dictionarymanager/beans/CodeTranslation.hbm.xml" />
       <mapping resource="com/phi/dictionarymanager/beans/CodeSystem.hbm.xml" />
      
      
       <event type="post-insert">
       <listener class="org.hibernate.envers.event.AuditEventListener" />
       </event>
       <event type="post-update">
       <listener class="org.hibernate.envers.event.AuditEventListener" />
       </event>
       <event type="post-delete">
       <listener class="org.hibernate.envers.event.AuditEventListener" />
       </event>
       <event type="pre-collection-update">
       <listener class="org.hibernate.envers.event.AuditEventListener" />
       </event>
       <event type="pre-collection-remove">
       <listener class="org.hibernate.envers.event.AuditEventListener" />
       </event>
       <event type="post-collection-recreate">
       <listener class="org.hibernate.envers.event.AuditEventListener" />
       </event>
      
      
       </session-factory>
      </hibernate-configuration>


      All the collections in this project are in mode lazy="true".

      Do someone of you know what kind of problem is this?

      Thank you in advance,
      Francesco.