[hibernate-dev] NaturalIdXrefDelegate key comparison issue

Eric Dalquist eric.dalquist at doit.wisc.edu
Sat Mar 10 23:37:50 EST 2012


I haven't spent a ton of time looking into this yet but while trying to 
update uPortal to use naturalIds in 4.1.1 I think I ran into a bug in: 
NaturalIdXrefDelegate$NaturalIdResolutionCache.areSame(Object[], Object[])

That code uses Type.compare(Object x, Object y) to compare each pair of 
fields in the two naturalIds.

I have an entity that has a field of type Class which ends up using the 
org.hibernate.type.ClassType.
ClassType relies on parent class AbstractStandardBasicType to implement 
the compare method.
AbstractStandardBasicType uses the JavaTypeDescriptor.getComparator() 
method to get the comparator to use.
For ClassType the JavaTypeDescriptor is 
org.hibernate.type.descriptor.java.ClassTypeDescriptor which never sets 
a comparator so JavaTypeDescriptor.getComparator() returns null 
resulting in the following NPE:

Caused by: java.lang.NullPointerException
     at 
org.hibernate.type.AbstractStandardBasicType.compare(AbstractStandardBasicType.java:210)
     at 
org.hibernate.engine.internal.NaturalIdXrefDelegate$NaturalIdResolutionCache.areSame(NaturalIdXrefDelegate.java:353)
     at 
org.hibernate.engine.internal.NaturalIdXrefDelegate$NaturalIdResolutionCache.cache(NaturalIdXrefDelegate.java:338)
     at 
org.hibernate.engine.internal.NaturalIdXrefDelegate.cacheNaturalIdResolution(NaturalIdXrefDelegate.java:78)
     at 
org.hibernate.engine.internal.StatefulPersistenceContext.entityStateUpdatedNotification(StatefulPersistenceContext.java:1732)
     at 
org.hibernate.engine.spi.EntityEntry.notifyLoadedStateUpdated(EntityEntry.java:382)
     at 
org.hibernate.engine.spi.EntityEntry.postUpdate(EntityEntry.java:244)
     at 
org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:152)
     at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
     at 
org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
     at 
org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:276)
     at 
org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
     at 
org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
     at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1127)
     at 
org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:325)
     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)

I likely won't have time to try and reproduce this in a hibernate unit 
test until Monday or Tuesday, I'm hoping someone might have a quick insight.

-Eric



More information about the hibernate-dev mailing list