Add documentation notes about LIST semantics for mappedBy mappings

This commit is contained in:
Christian Beikov 2022-02-02 19:53:29 +01:00
parent a91d23825f
commit 8183901cfe
1 changed files with 7 additions and 0 deletions

View File

@ -92,6 +92,13 @@ To maintain the order, it is necessary to explicitly use the `jakarta.persistenc
Starting in 6.0, Hibernate allows to configure the default semantics of `List` without `@OrderColumn`
via the `hibernate.mapping.default_list_semantics` setting.
To switch to the more natural LIST semantics with an implicit order-column, set the setting to `LIST`.
Beware that default LIST semantics only affects owned collection mappings.
Unowned mappings like `@ManyToMany(mappedBy = "...")` and `@OneToMany(mappedBy = "...")` do not retain the element
order by default, and explicitly annotating `@OrderColumn` for `@ManyToMany(mappedBy = "...")` mappings is illegal.
To retain the order of elements of a `@OneToMany(mappedBy = "...")` the `@OrderColumn` annotation must be applied
explicitly. In addition to that, it is important that both sides of the relationship, the `@OneToMany(mappedBy = "...")`
and the `@ManyToOne`, must be kept in sync. Otherwise, the element position will not be updated accordingly.
The default column name that stores the index is derived from the attribute name, by suffixing `_ORDER`.
====