, , , .
, . , , , , MappedBy :
@Entity
@Table(name="PERSONS")
public class Person {
@OneToMany
private List<IdDocument> idDocuments;
}
@Entity
@Table(name="IDDOCUMENT")
public class IdDocument {
@ManyToOne
private Person person;
}
PERSONS IDDOCUMENTS, PERSONS_IDDOCUMENTS:
CREATE TABLE persons_iddocument
(
persons_id bigint NOT NULL,
iddocuments_id bigint NOT NULL,
CONSTRAINT fk_persons FOREIGN KEY (persons_id) REFERENCES persons (id),
CONSTRAINT fk_docs FOREIGN KEY (iddocuments_id) REFERENCES iddocument (id),
CONSTRAINT pk UNIQUE (iddocuments_id)
)
. Hibernate : Person.idDocuments, PERSON_IDDOCUMENTS.
Person of IdDocument, person_id IDDOCUMENTS.
Hibernate ( ) , , .
, . IDDOCUMENTS to PERSON: .
, Person.idDocuments, IdDocument.person , .
, Hibernate, Person.idDocuments. Hibernate IdDocument.person, mappedBy:
@OneToMany(mappedBy="person")
private List<IdDocument> idDocuments;
This means that "the modifications on this side of the relationship are already mapped to the other side of the IdDocument.person relationship, so there is no need to track it here separately in the additional table."
This gives us the mapping we need, but has one important consequence:
- Changes to the Person.idDocuments collection are no longer tracked by Hibernate, and the developer should change IdDocument.person instead to change the association.