Boot-time mapping checks dereference null and throw NullPointerException before they can reject a mapping

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: Model
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      MongoAdditionalMappingContributor already checks the two mappings below and would reject both,
      but it dereferences a null on the way to the decision. The result is a NullPointerException
      naming an internal Hibernate ORM type instead of a FeatureNotSupportedException naming the
      unsupported mapping. Both cases are null guards on the same checking path.

      Case 1: non-aggregated composite identifier (@IdClass)

      A non-aggregated composite identifier leaves PersistentClass.getIdentifierProperty() null, which
      MongoAdditionalMappingContributor.checkPropertyTypes passes straight to checkPropertyType.

      @Entity @Table(name = "items")
      @IdClass(ItemId.class)
      static class ItemWithIdClass {
          @Id @ManyToOne @JoinColumn(name = "owner_id") Owner owner;
          @Id int itemId;
      }
      
      java.lang.NullPointerException: Cannot invoke "org.hibernate.mapping.Property.getName()" because "property" is null
        at com.mongodb.hibernate.internal.boot.MongoAdditionalMappingContributor.checkPropertyType(MongoAdditionalMappingContributor.java:304)
        at com.mongodb.hibernate.internal.boot.MongoAdditionalMappingContributor.checkPropertyTypes(MongoAdditionalMappingContributor.java:239)
      

      A multi-column primary key is already rejected with FeatureNotSupportedException in
      AbstractMqlTranslator.createKeyFilter, so declaring one with @IdClass should be rejected the
      same way until HIBERNATE-206 and HIBERNATE-207 land.

      Case 2: dynamic model entity

      An entity declared without a class is a dynamic model, whose attributes report a null Java type.
      MongoAdditionalMappingContributor.forbidUnsupportedTypes passes that to Set.of(...).contains,
      which rejects null.

      <entity-mappings xmlns="http://www.hibernate.org/xsd/orm/mapping" version="7.0">
          <entity name="Employee" metadata-complete="true">
              <attributes>
                  <id name="id"><target>Integer</target></id>
                  <basic name="name"><target>String</target></basic>
              </attributes>
          </entity>
      </entity-mappings>
      
      java.lang.NullPointerException
        at java.base/java.util.Objects.requireNonNull(Objects.java:209)
        at java.base/java.util.ImmutableCollections$SetN.contains(ImmutableCollections.java:937)
        at com.mongodb.hibernate.internal.boot.MongoAdditionalMappingContributor.forbidUnsupportedTypes(MongoAdditionalMappingContributor.java:332)
      

      Proposed fix

      Guard both sites and throw FeatureNotSupportedException naming the unsupported mapping.

      Acceptance

      Both mappings are rejected with FeatureNotSupportedException whose message names the unsupported
      mapping.

            Assignee:
            Unassigned
            Reporter:
            Jeffrey Yemin
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: