add a TIP about @OneToOne mappings

This commit is contained in:
Gavin King 2024-02-14 12:04:43 +01:00
parent 914227de93
commit b4b4112f75
1 changed files with 21 additions and 0 deletions

View File

@ -517,6 +517,27 @@ class Book {
Again, the `foreignKey` member is optional. Again, the `foreignKey` member is optional.
[TIP]
====
For mapping a `@OneToOne` association <<one-to-one-pk,to a primary key>> with `@MapsId`, Hibernate lets us use either `@JoinColumn` or `@PrimaryKeyJoinColumn`.
[source,java]
----
@Entity
class Author {
@Id
Long id;
@OneToOne(optional=false, fetch=LAZY)
@MapsId
@PrimaryKeyJoinColumn(name="personId")
Person author;
...
}
----
Arguably, the use of `@PrimaryKeyJoinColumn` is clearer.
====
[[primary-key-column-mappings]] [[primary-key-column-mappings]]
=== Mapping primary key joins between tables === Mapping primary key joins between tables