-
Type:
Improvement
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: Model
-
None
Problem
A schema folds into the collection name as schema.name, so a '.' written by the
user collides with the extension's own separator. Two distinct table qualifiers
resolve to one collection:
@Table(schema = "a", name = "b") // collection a.b @Table(name = "a.b") // collection a.b
Hibernate ORM keeps these as two distinct tables and does not object. Both
entities read and write the same collection.
A dotted table name leaks a schema into the entity's generated sequence, i.e:
@Table(name = "a.b") with @GeneratedValue table: schema=null name=a.b sequence: schema=a name=b_SEQ sequence document _id becomes "a.b_SEQ"
The table treats a.b as one opaque name with no schema. The sequence derived
from that same table treats a as a schema. That sequence document _id is the same one
produced by an unrelated @SequenceGenerator(schema = "a", sequenceName =
"b_SEQ"), and Hibernate ORM merges the two into a single sequence, so two
unrelated entities can silently allocate identifiers from one counter. See
HIBERNATE-233 for sequence-style identifier generation.
Proposal
Reject a '.' in a table name and in a schema name at boot, in
MongoAdditionalMappingContributor. Two different table qualifiers can then
never resolve to the same collection name, and the implicit sequence name
derived from a table can no longer contain a '.'.
Scope
Reject:
* a '.' in a table name, including secondary, join, and collection tables
* a '.' in a schema name, whether from the schema attribute or from
hibernate.default_schema
Remove:
* the resolved-name collision check, which exists only to catch this
Compatibility
This removes a currently supported and tested capability: a collection name
containing a '.' can no longer be written directly as a table name.
Collection names with exactly one '.' are still allowed through the schema
attribute, which is the same physical collection:
@Table\(name = "archive.entries"\) // before @Table\(schema = "archive", name = "entries"\) // after, same collection
Collection names with two or more dots become unmappable.
Documentation
Note that a '.' is not permitted in a table or schema name, and that a
schema-qualified entity maps to the collection named schema.name.