[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6960) NullPointerException in PreCollectionRemove Listener
Stefan Hildebrandt (JIRA)
noreply at atlassian.com
Wed Apr 25 14:57:52 EDT 2012
[ https://hibernate.onjira.com/browse/HHH-6960?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46425#comment-46425 ]
Stefan Hildebrandt commented on HHH-6960:
-----------------------------------------
Some debugging:
collectionEntry lockes like this:
collectionEntry = org.hibernate.engine.spi.CollectionEntry at 7952
snapshot = null
role = null
loadedPersister = null
loadedKey = null
reached = false
processed = true
doupdate = false
doremove = true
docreate = false
ignore = false
currentPersister = null
currentKey = null
Looks like a remove event. Possible there was a remove event within a prior flush, thats removed the entity.
Code that checks this:
{code}
private static final IdentityHashMap<PersistentCollection, CollectionEntry> identityHashMap
= new IdentityHashMap<PersistentCollection, CollectionEntry>();
@Override
public void onPreRemoveCollection(PreCollectionRemoveEvent event) {
CollectionEntry collectionEntry = getCollectionEntry( event );
if ( collectionEntry != null
&& !(collectionEntry.isDoremove() &&identityHashMap.containsKey(event.getCollection()))
&& !collectionEntry.getLoadedPersister().isInverse() ) {
onCollectionAction( event, null, collectionEntry.getSnapshot(), collectionEntry );
}
if(collectionEntry.isDoremove()){
identityHashMap.put(event.getCollection(), collectionEntry);
}
}
{code}
All Tests are running!
After that, the following code seams to be save.
{code}
@Override
public void onPreRemoveCollection(PreCollectionRemoveEvent event) {
CollectionEntry collectionEntry = getCollectionEntry( event );
if ( collectionEntry != null
&& !(collectionEntry.getCurrentPersister() == null && collectionEntry.isDoremove() && collectionEntry.isProcessed())
&& !collectionEntry.getLoadedPersister().isInverse() ) {
onCollectionAction( event, null, collectionEntry.getSnapshot(), collectionEntry );
}
if(collectionEntry.isDoremove()){
identityHashMap.put(event.getCollection(), collectionEntry);
}
}
{code}
> NullPointerException in PreCollectionRemove Listener
> ----------------------------------------------------
>
> Key: HHH-6960
> URL: https://hibernate.onjira.com/browse/HHH-6960
> Project: Hibernate ORM
> Issue Type: Bug
> Components: envers
> Affects Versions: 4.0.0.Final
> Environment: Hibernate 4.0.0 to MySQL
> Reporter: Kevin Jordan
> Assignee: Gail Badner
>
> I'm getting a NullPointerException on line 47 of EnversPreCollectionRemoveEventListenerImpl very consistently. I wasn't sure if it was due to lazy collections or not, but it seems that it fails if they're eagerly fetched or lazily fetched. I'm guessing it has something to do with getLoadedPersister() returning a null value since the comments for it say "This is only available late during the flush cycle". The stack trace is
> Quote:
> java.lang.NullPointerException
> at org.hibernate.envers.event.EnversPreCollectionRemoveEventListenerImpl.onPreRemoveCollection(EnversPreCollectionRemoveEventListenerImpl.java:47)
> at org.hibernate.action.internal.CollectionRemoveAction.preRemove(CollectionRemoveAction.java:143)
> at org.hibernate.action.internal.CollectionRemoveAction.execute(CollectionRemoveAction.java:104)
> at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:273)
> at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:265)
> at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:188)
> at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:323)
> at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
> at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1081)
> at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:315)
> at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
> at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
> at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:73)
> ... 120 more
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list