Questo contenuto non è disponibile nella lingua selezionata.
7.4. Bidirectional associations
7.4.1. one-to-many / many-to-one Copia collegamentoCollegamento copiato negli appunti!
Copia collegamentoCollegamento copiato negli appunti!
A bidirectional many-to-one association is the most common kind of association. The following example illustrates the standard parent/child relationship.
create table Person ( personId bigint not null primary key, addressId bigint not null ) create table Address ( addressId bigint not null primary key )
create table Person ( personId bigint not null primary key, addressId bigint not null )
create table Address ( addressId bigint not null primary key )
If you use a
List
, or other indexed collection, set the key
column of the foreign key to not null
. Hibernate will manage the association from the collections side to maintain the index of each element, making the other side virtually inverse by setting update="false"
and insert="false"
:
If the underlying foreign key column is
NOT NULL
, it is important that you define not-null="true"
on the <key>
element of the collection mapping. Do not only declare not-null="true"
on a possible nested <column>
element, but on the <key>
element.