NullPointerException merging entity with a lazy to-many association in Hibernate

Solution In Progress - Updated -

Issue

  • Entity has a lazy to-many association which is un-initialized
  • Encountering a NullPointerException when merging the entity

    ... java.lang.NullPointerException
        at org.hibernate.type.EntityType.replace(EntityType.java:313)
        at org.hibernate.collection.internal.AbstractPersistentCollection$AbstractValueDelayedOperation.getReplacement(AbstractPersistentCollection.java:1164)
        at org.hibernate.collection.internal.AbstractPersistentCollection$AbstractValueDelayedOperation.replace(AbstractPersistentCollection.java:1159)
        at org.hibernate.collection.internal.AbstractPersistentCollection.replaceQueuedOperationValues(AbstractPersistentCollection.java:489)
        at org.hibernate.type.CollectionType.replace(CollectionType.java:652)
        at org.hibernate.type.TypeHelper.replace(TypeHelper.java:177)
        at org.hibernate.event.internal.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:393)
        at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:327)
        at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:169)
        at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:68)
        at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:843)
        at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:825)
        at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:830)
        at org.hibernate.jpa.spi.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:1161)
        at org.jboss.as.jpa.container.AbstractEntityManager.merge(AbstractEntityManager.java:565)
    

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 7
  • Hibernate 5

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In