Uploaded image for project: 'Hibernate ORM'
  1. Hibernate ORM
  2. HHH-11502

XML Mapped Entity with a ManyToOne association to a Annotation Mapped Entity -> NullPointerException

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.2.8
    • Fix Version/s: 5.2.9, 5.1.8
    • Component/s: hibernate-core
    • Labels:
      None
    • Environment:
      Hibernate 5.2.8
      PostgreSQL 9.5.5
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Worked in:
    • Last commented by a user?:
      true

      Description

      We're upgrading from Hibernate 4.3.11 to Hibernate 5.2.7 and are getting a NullPointerException in ModelBinder when it tries to access a PrimaryKey. It's null.

      We have a mix of HBM and Annotation entities. It happens when an entity is mapped via XML and references an entity that is mapped via annotations - many to one. We're using the legacy bootstrapping process via spring's LocalSessionFactoryBuilder (version 5). I've tried changing to non-legacy native bootstrapping, but that made no difference.

      Here's the exception:

      NPE in ModelBinder
      Caused by: java.lang.NullPointerException
              at org.hibernate.boot.model.source.internal.hbm.ModelBinder$ManyToOneColumnBinder.doSecondPass(ModelBinder.java:4140) ~[hibernate-core-5.2.7.Final.jar:5.2.7.Final]
              at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1621) ~[hibernate-core-5.2.7.Final.jar:5.2.7.Final]
              at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1576) ~[hibernate-core-5.2.7.Final.jar:5.2.7.Final]
              at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:278) ~[hibernate-core-5.2.7.Final.jar:5.2.7.Final]
              at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83) ~[hibernate-core-5.2.7.Final.jar:5.2.7.Final]
              at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418) ~[hibernate-core-5.2.7.Final.jar:5.2.7.Final]
              at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87) ~[hibernate-core-5.2.7.Final.jar:5.2.7.Final]
              at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691) ~[hibernate-core-5.2.7.Final.jar:5.2.7.Final]
              at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726) ~[hibernate-core-5.2.7.Final.jar:5.2.7.Final]
              at com.i2rd.hibernate.util.RebuildableSessionFactoryBean.createSessionFactory(RebuildableSessionFactoryBean.java:242) ~[net.proteusframework-core.jar:?]
              at com.i2rd.hibernate.util.RebuildableSessionFactoryBean.rebuildSessionFactory(RebuildableSessionFactoryBean.java:204) ~[net.proteusframework-core.jar:?]
              at com.i2rd.hibernate.util.RebuildableSessionFactoryBean.getObject(RebuildableSessionFactoryBean.java:182) ~[net.proteusframework-core.jar:?]
              at com.i2rd.hibernate.util.RebuildableSessionFactoryBean.getObject(RebuildableSessionFactoryBean.java:54) ~[net.proteusframework-core.jar:?]
              at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
      

      Originally posted here: https://forum.hibernate.org/viewtopic.php?f=1&t=1044033

      I worked around it in the short-term by changing ModelBinder to create the primary key on-demand if it doesn't exist. https://github.com/rtennantventuretech/hibernate-orm/commit/c2bf4b808259c8a56bc494ece7a4ba50874793ec

      Test case: https://github.com/hibernate/hibernate-orm/pull/1796

        Attachments

          Issue links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: