[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3884) NullPointerException with mutable Natural IDs
Gail Badner (JIRA)
noreply at atlassian.com
Tue May 11 22:38:23 EDT 2010
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3884?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=37068#action_37068 ]
Gail Badner commented on HHH-3884:
----------------------------------
Please do the following:
- checkout the trunk version http://anonsvn.jboss.org/repos/hibernate/core/trunk
- update a test in testsuite/src/test/java/org/hibernate/test/naturalid/immutable/ to reproduce your issue
- create a patch using "svn diff" and attach to this issue
Thanks,
Gail
> NullPointerException with mutable Natural IDs
> ---------------------------------------------
>
> Key: HHH-3884
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3884
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.2.2, 3.5.1
> Reporter: Michael Kopp
>
> When saving an entity with a mutable natural id hibernate throws the following NPE.
> java.lang.NullPointerException
> at org.hibernate.engine.StatefulPersistenceContext.getNaturalIdSnapshot(StatefulPersistenceContext.java:267)
> at org.hibernate.event.def.DefaultFlushEntityEventListener.checkNaturalId(DefaultFlushEntityEventListener.java:78)
> at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:162)
> at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113)
> at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
> at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
> at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
> at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
> I checked the code and found the reason:
> - getNaturalIdSnapshot calls getDatabaseSnapshot and checks the result for NO_ROW but not for null
> - getDatabaseSnapshot will never return NO_ROW but null if nothing was found
> hence getNaturalIdSnapshot will produce a NPE if the entity is not in the database already.
> the fix is simple:
> change:
> Object[] entitySnapshot = getDatabaseSnapshot( id, persister );
> if ( entitySnapshot == NO_ROW ) {
> return null;
> }
> to
> Object[] entitySnapshot = getDatabaseSnapshot( id, persister );
> if ( entitySnapshot == null ) {
> return null;
> }
> This is still there in trunk as well!
--
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