throw exception when id column name is specified explicitly and different from _id

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Minor - P4
    • 1.0.0
    • Affects Version/s: None
    • Component/s: Model
    • None
    • 3
    • None
    • Needed
    • Hide

      Complexity: Simple (one new mapping constraint + its error; small addition to one page)

      Model Your Data: an entity's @Id must map to the _id field. Explicitly naming the id column anything else via @Column(name=...) (or an orm.xml <column> override) fails fast at bootstrap with an actionable FeatureNotSupportedException (the message echoes the offending name). Known gap to document: legacy HBM XML mappings are silently renamed to _id rather than rejected.

      Show
      Complexity: Simple (one new mapping constraint + its error; small addition to one page) Model Your Data: an entity's @Id must map to the _id field. Explicitly naming the id column anything else via @Column(name=...) (or an orm.xml <column> override) fails fast at bootstrap with an actionable FeatureNotSupportedException (the message echoes the offending name). Known gap to document: legacy HBM XML mappings are silently renamed to _id rather than rejected.
    • None
    • None
    • None
    • None
    • None
    • None

      Throw FeatureNotSupportedException at bootstrap when a JPA entity explicitly maps its @Id column to a name other than _id.

      MongoDB requires the primary key field to be named _id. Previously, any explicitly-set name was silently overridden. This change detects the misconfiguration early and tells the user how to fix it.

      Scope

      Mapping style Covered
      JPA @Column(name = "...") on @Id field
      JPA orm.xml <column name="..."/> override ✅ (Hibernate merges orm.xml into the same annotation model before bootstrap validation runs)
      Legacy HBM XML ❌ — HBM XML is deprecated and scheduled for removal in Hibernate 8.0. MemberDetails is null for HBM-sourced mappings so there is no clean detection mechanism; the column name is still silently renamed to _id.

      Implementation

      The guard is in MongoAdditionalMappingContributor.setIdentifierColumnName. Before the unconditional rename to _id, it checks whether the identifier is a SimpleValue with non-null MemberDetails carrying a @Column annotation with a non-blank name. If so, it throws with an actionable message that names the offending value and tells the user to remove or correct the annotation.

            Assignee:
            Jeffrey Yemin
            Reporter:
            Nathan Xu (Inactive)
            Andre Masella
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: