Own Party versus Non-Property Party In sleep mode and its use in relation to matching using an element?

I learned the terms ie owning side and non-owningwhile studying sleep mode. For example: - here is a statement about the use of the displayed element in terms of its use in a one-to-one mapping

If the relationship is bidirectional, the non-owner must use mappedBythe annotation element OneToOneto indicate the relationship field or property of the party.

But I did not understand that there really is a side owning side and non-owning?

+1
source share
3 answers

, ( " " )

                       corresponds to       
College(Value Object) -----------------> College (Database Table)

                       corresponds to       
Student(Value Object) -----------------> Student (Database Table having column which is
                                                  foreign key to College table . 
                                                  So This is owning side and College  is
                                                  Non-owning side )

- , , . .

@Entity
public class College {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int collegeId;
    @OneToMany(mappedBy="college") // here non-owning side using mapped by elment to specify
                                   // the relationship field of owning side
    private List<Student> students;
    }


Owning Side Object

@Entity
public class Student {
@ManyToOne
    private College college;
}

- , . , , .

: - , . , , , @joincolumn, . . @OneToOne

+1

"" - , .

" " EntityPerson EntityAddress, , EntityPerson -, -

 ADDRESS_ID int NULL FOREIGN KEY REFERENCES Address (ID)
+3

, , , .

, . , , , , 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.
+2
source

Source: https://habr.com/ru/post/1524849/


All Articles