[hibernate-issues] [Hibernate-JIRA] Updated: (HHH-3847) java.lang.NullPointerException on onPreRemoveCollection on replicate of persistent class
Jesse Jose C (JIRA)
noreply at atlassian.com
Mon May 18 21:07:14 EDT 2009
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3847?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jesse Jose C updated HHH-3847:
------------------------------
Attachment: HHH-3847patch.txt
Hiya,
I came across this problem as well, and this time iwas a basic saveOrUpdate call where a Child association is null on the first save and the subsequent update adds adds an object into the association. In that scenario the pre remove collection is Null, which is the root cause of the problem. Attached is a patch which fixes the problem for us. I changed the public void onPreRemoveCollection(PreCollectionRemoveEvent event) in the AuditEventListener class to check for nulls as below
public void onPreRemoveCollection(PreCollectionRemoveEvent event) {
CollectionEntry collectionEntry = getCollectionEntry(event);
if (collectionEntry!=null && !collectionEntry.getLoadedPersister().isInverse()) {
onCollectionAction(event, null, collectionEntry.getSnapshot(), collectionEntry);
}
}
Hopefully this solution is the correct way forward ?
Cheers
Jesse
> java.lang.NullPointerException on onPreRemoveCollection on replicate of persistent class
> ----------------------------------------------------------------------------------------
>
> Key: HHH-3847
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3847
> Project: Hibernate Core
> Issue Type: Bug
> Components: envers
> Affects Versions: 3.3.1
> Environment: Envers 1.2, Hibernate 3.3.1 on Mysql and Hsql.
> Reporter: Francesco Di Salvatore
> Priority: Critical
> Attachments: HHH-3847patch.txt, TestEnvers12.zip
>
>
> I get this exception when trying to REPLICATE an object in a synchronized database:
> Code:
> 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(AbstractFlushingEventLis
> tener.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.jav
> a:92)
> at com.phi.dictionarymanager.ui.widgets.VocabolaryItemNewComposite.save(VocabolaryItemNewComposite.
> java:515)
> at com.phi.dictionarymanager.ui.widgets.VocabularyDomainsNavigatorComposite$18.handleEvent(Vocabula
> ryDomainsNavigatorComposite.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.j
> ava: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:
> Code:
> 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):
> Code:
> <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".
> In the first saving the onPreRemoveCollection method is never called.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list