[
https://hibernate.onjira.com/browse/HHH-7241?page=com.atlassian.jira.plug...
]
Donnchadh O Donnabhain commented on HHH-7241:
---------------------------------------------
This is the stack trace I get:
{noformat}
java.lang.NullPointerException
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:768)
at
org.hibernate.engine.internal.NaturalIdXrefDelegate$NaturalIdResolutionCache.cache(NaturalIdXrefDelegate.java:454)
at
org.hibernate.engine.internal.NaturalIdXrefDelegate.cacheNaturalIdCrossReference(NaturalIdXrefDelegate.java:92)
at
org.hibernate.engine.internal.StatefulPersistenceContext$1.manageLocalNaturalIdCrossReference(StatefulPersistenceContext.java:1769)
at
org.hibernate.action.internal.AbstractEntityInsertAction.handleNaturalIdPreSaveNotifications(AbstractEntityInsertAction.java:184)
at
org.hibernate.action.internal.AbstractEntityInsertAction.<init>(AbstractEntityInsertAction.java:75)
at
org.hibernate.action.internal.EntityIdentityInsertAction.<init>(EntityIdentityInsertAction.java:55)
at
org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:317)
at
org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:287)
at
org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:193)
at
org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
at
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204)
at
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189)
at
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:114)
at
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:695)
at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:687)
at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:683)
{noformat}
Would it be reasonable to just add a null check at the beginning of
{{NaturalIdResolutionCache.cache}} ?
Obviously the newly-saved object won't be cached but that seems better than throwing
an exception. Ideally the call to {{NaturalIdResolutionCache.cache}} would be delayed
until the id value is known.
{code}
public boolean cache(Serializable pk, Object[] naturalIdValues) {
final CachedNaturalId initial = pkToNaturalIdMap.get( pk );
if ( initial != null ) {
if ( initial.isSame( naturalIdValues ) ) {
return false;
}
naturalIdToPkMap.remove( initial );
}
final CachedNaturalId cachedNaturalId = new CachedNaturalId( persister,
naturalIdValues );
pkToNaturalIdMap.put( pk, cachedNaturalId );
naturalIdToPkMap.put( cachedNaturalId, pk );
return true;
}
{code}
NPE in NaturalIdResolutionCache
-------------------------------
Key: HHH-7241
URL:
https://hibernate.onjira.com/browse/HHH-7241
Project: Hibernate ORM
Issue Type: Bug
Affects Versions: 4.1.2
Environment: Hibernate 4.1.2, hsqldb 2.2.8
Reporter: Neukomm
Attachments: NaturalIdResolutionCacheNPETest.zip
Starting with hibernate-core version 4.1.2,
NaturalIdXrefDelegate$NaturalIdResolutionCache.cache throws NullPointerException in cases
where the id is not yet known. hibernate-core 4.1.1 works fine.
I've attached a test case that fails in 4.1.2, but runs fine with 4.1.1.
This issue was already mentioned in the user forum:
https://forum.hibernate.org/viewtopic.php?f=1&t=1015088
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira