Re-write of `Collections` domain model section

preliminary work
This commit is contained in:
Steve Ebersole 2021-12-31 16:37:55 -06:00
parent 7c475c8ac0
commit 7599d3b2dd
1 changed files with 66 additions and 25 deletions

View File

@ -36,34 +36,70 @@ the capabilities of the mapping such as
* how to access elements of the collection * how to access elements of the collection
* how to create instances of the collection - both "raw" and "wrapper" forms. See <<collection-wrapper>> * how to create instances of the collection - both "raw" and "wrapper" forms. See <<collection-wrapper>>
ARRAY:: Hibernate is able to map Object and primitive arrays as collections. The major
limitation to such a mapping is that the collection cannot be lazy in its wrapped form. However, [[collection-semantics-array]]
it can be lazy via bytecode enhancement of its owner. Note that Jakarta Persistence does not ===== ARRAY
define support for arrays as plural attributes; in strict JPA mode these would be mapped as binary
data. Hibernate is able to map Object and primitive arrays as collections. The major
BAG:: A collection that may contain duplicate entries and has no defined ordering. Conceptually limitation to such a mapping is that the collection cannot be lazy in its wrapped form. However,
it is a `java.util.Collection` that is not a further subtype. Jakarta Persistence does not define it can be lazy via bytecode enhancement of its owner. Note that Jakarta Persistence does not
support for this semantic. define support for arrays as plural attributes; in strict JPA mode these would be mapped as binary
ID_BAG:: A bag that defines a per-element identifier to uniquely identify elements in the collection. data.
The identifier is configured via `org.hibernate.annotations.CollectionId`.
LIST:: Follows the semantics defined by `java.util.List`. It is a collection that is ordered based
on a column in the database which contains the element's position in the list. The "position" column [[collection-semantics-bag]]
is specified using either `jakarta.persistence.OrderColumn` or `org.hibernate.annotations.IndexColumn`; ===== BAG
`jakarta.persistence.OrderColumn` should be preferred. By default, Hibernate stores the position of the
elements in the list starting from `0`; for pre-existing schemas that use a different "base", Hibernate A collection that may contain duplicate entries and has no defined ordering. Conceptually
provides the `org.hibernate.annotations.ListIndexBase` annotation. A list may contain duplicate entries. it is a `java.util.Collection` that is not a further subtype. Jakarta Persistence does not define
SET:: support for this semantic.
ORDERED_SET::
SORTED_SET::
MAP:: [[collection-semantics-idbag]]
ORDERED_MAP:: ===== ID_BAG
SORTED_MAP::
A bag that defines a per-element identifier to uniquely identify elements in the collection.
The identifier is configured via `org.hibernate.annotations.CollectionId`.
[[collection-semantics-list]]
===== LIST
Follows the semantics defined by `java.util.List`. It is a collection that is ordered based
on a column in the database which contains the element's position in the list. The "position" column
is specified using either `jakarta.persistence.OrderColumn` or `org.hibernate.annotations.IndexColumn`;
`jakarta.persistence.OrderColumn` should be preferred. By default, Hibernate stores the position of the
elements in the list starting from `0`; for pre-existing schemas that use a different "base", Hibernate
provides the `org.hibernate.annotations.ListIndexBase` annotation. A list may contain duplicate entries.
NOTE:: Historically, Hibernate interpreted a `List` attribute without `@OrderColumn` or `@IndexColumn` NOTE:: Historically, Hibernate interpreted a `List` attribute without `@OrderColumn` or `@IndexColumn`
as BAG. This is not the most natural choice, but exists for backwards compatibility. For those as BAG. This is not the most natural choice, but exists for backwards compatibility. For those
wanting the more natural choice to use LIST semantics here, set `hibernate.mapping.default_list_semantics=list` wanting the more natural choice to use LIST semantics here, set `hibernate.mapping.default_list_semantics=list`
[[collection-semantics-set]]
===== SET
[[collection-semantics-ordered_set]]
ORDERED_SET::
[[collection-semantics-sorted-set]]
SORTED_SET::
[[collection-semantics-map]]
MAP::
[[collection-semantics-ordered-map]]
ORDERED_MAP::
[[collection-semantics-sorted-map]]
SORTED_MAP::
See
[[collection-nature]] [[collection-nature]]
@ -115,11 +151,16 @@ Hibernate provides 3 ways to influence the semantics used for a collection mappi
todo (6.0) - finish todo (6.0) - finish
[[NOTE]] [[NOTE]]
---- ----
Original content below Original content below
---- ----
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Naturally Hibernate also allows persisting collections. Naturally Hibernate also allows persisting collections.
These persistent collections can contain almost any other Hibernate type, including basic types, custom types, embeddables, and references to other entities. These persistent collections can contain almost any other Hibernate type, including basic types, custom types, embeddables, and references to other entities.
In this context, the distinction between value and reference semantics is very important. In this context, the distinction between value and reference semantics is very important.