NullPointerException deploying persistence unit with a map collection indexed using an Embeddable with an association to the entity which owns the map in JBoss EAP

Solution Verified - Updated

Environment

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

Issue

  • A Map association is defined between two entities as below

        @Embeddable
        public class TheMapKey implements Serializable {
            @ManyToOne
            private TheOne theOne;
        }
    
        @Entity
        public class TheOne {
            @Id
            private String id;
    
            @OneToMany(mappedBy = "theMapKey.theOne")
            @MapKey(name = "theMapKey")
            private Map<TheMapKey, TheMany> theManys = new HashMap<>();
        }
    
        @Entity
        public static class TheMany {
            @EmbeddedId
            private TheMapKey theMapKey;
        }
    
  • During build of the entity manager factory an exception is raised

    ... javax.persistence.PersistenceException: [PersistenceUnit: XXX] Unable to build Hibernate SessionFactory
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1327)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1253)
        at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:167)
        ... 9 more
    Caused by: java.lang.NullPointerException
        at org.hibernate.loader.plan.build.internal.AbstractLoadPlanBuildingAssociationVisitationStrategy.foundCircularAssociation(AbstractLoadPlanBuildingAssociationVisitationStrategy.java:669)
        at org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAttributeDefinition(MetamodelGraphWalker.java:148)
        at org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAttributes(MetamodelGraphWalker.java:133)
        at org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitCompositeDefinition(MetamodelGraphWalker.java:209)
        at org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitCollectionIndex(MetamodelGraphWalker.java:240)
        at org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitCollectionDefinition(MetamodelGraphWalker.java:217)
        at org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitCollection(MetamodelGraphWalker.java:73)
        at org.hibernate.loader.plan.build.spi.MetamodelDrivenLoadPlanBuilder.buildRootCollectionLoadPlan(MetamodelDrivenLoadPlanBuilder.java:54)
        at org.hibernate.loader.collection.plan.AbstractLoadPlanBasedCollectionInitializer.<init>(AbstractLoadPlanBasedCollectionInitializer.java:61)
        at org.hibernate.loader.collection.plan.CollectionLoader.<init>(CollectionLoader.java:81)
        at org.hibernate.loader.collection.plan.CollectionLoader$Builder.byKey(CollectionLoader.java:74)
        at org.hibernate.loader.collection.plan.AbstractBatchingCollectionInitializerBuilder.buildNonBatchingLoader(AbstractBatchingCollectionInitializerBuilder.java:28)
        at org.hibernate.loader.collection.BatchingCollectionInitializerBuilder.createBatchingOneToManyInitializer(BatchingCollectionInitializerBuilder.java:85)
        at org.hibernate.persister.collection.OneToManyPersister.createCollectionInitializer(OneToManyPersister.java:513)
        at org.hibernate.persister.collection.AbstractCollectionPersister.postInstantiate(AbstractCollectionPersister.java:668)
        at java.util.concurrent.ConcurrentHashMap$ValuesView.forEach(ConcurrentHashMap.java:4707) [rt.jar:1.8.0_222]
        at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:233)
        at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:295)
        at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1250)
        ...
    
  • The schema deployed without an exception in EAP 6 / Hibernate 4

Resolution

This issue1 is resolved in This content is not included.EAP 7.3 cumulative patch (CP) 5 and later releases. Production systems should use the latest available cumulative patch.

Root Cause

This is a known defect (Content from hibernate.atlassian.net is not included.HHH-14257).

Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.