java.lang.NullPointerException

Hibernate JIRA | Michael Kopp | 8 years ago
  1. 0

    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!

    Hibernate JIRA | 8 years ago | Michael Kopp
    java.lang.NullPointerException
  2. 0

    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!

    Hibernate JIRA | 8 years ago | Michael Kopp
    java.lang.NullPointerException
  3. 0

    Android: Saving Map State in Google map

    Stack Overflow | 11 months ago | Junie Negentien
    java.lang.RuntimeException: Unable to resume activity {com.ourThesis.junieNegentien2015/com.ourThesis.junieNegentien2015.MainActivity}: java.lang.NullPointerException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at org.hibernate.engine.StatefulPersistenceContext.getNaturalIdSnapshot()
    2. Hibernate
      StatefulPersistenceContext.getNaturalIdSnapshot
      1. org.hibernate.engine.StatefulPersistenceContext.getNaturalIdSnapshot(StatefulPersistenceContext.java:267)
      1 frame
    3. Hibernate
      SessionImpl.flush
      1. org.hibernate.event.def.DefaultFlushEntityEventListener.checkNaturalId(DefaultFlushEntityEventListener.java:78)
      2. org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:162)
      3. org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113)
      4. org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
      5. org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
      6. org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
      7. org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
      7 frames