Hi community,
I dont understand the relationship principe of JPA.
There is OneToMany
, ManyToOne
, OneToMany
and ManyToMany
annotation.
If I use OneToMany and ManyToOne,
normally, I only “mark” one entity, the one, which contains “1” entity of other reference.
But for example in OneToOne annotation:
//Class Person
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = false, orphanRemoval = true)
Person personA;
//Class Teacher
@OneToOne(mappedBy="personA", cascade=CascadeType.ALL)
Teacher b;
Why does I have to mark the teacher class too?
Is this not enough?
//Class Person
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = false, orphanRemoval = true)
Person personA;
And how do I have to modify sql scripts?
Does I need a column of both?
Thanks a lot