-
Type:
Improvement
-
Resolution: Fixed
-
Priority:
Minor - P4
-
Affects Version/s: None
-
Component/s: Model
-
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.
- is related to
-
HIBERNATE-25 hardcode _id as collection primary key field name
-
- Closed
-