1)Entity RelationShip types = @OneToOne , @OneToMany, @ManyToOne, @ManyToMany
2)direction : bidirectional, unidirectional
3)Entity Relation Attributes
1: CascadeType: 연관된 것도 동일 적용 할 것 인지 //부모쪽에 주로 넣기
ALL, PERSIST,MERGE,REMOVE,REFRESH
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
2: FetchType : 연관된 것도 로드할 것 인지 LAZY=로드 적용 x , EAGER= 로드 동일 적용
@OneToMany, @ManyToMany = FetchType.LAZY
@OneToOne, @ManyToOne= FetchType.EAGER
4)OneToMany Unidirectional
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="category_id")
private Category category
-외래키는 Many(child)쪽에 둘 것 parent=One 쪽, childe= Many쪽
-@ManyToOne =Many 쪽이고 child구나라고 hibernate가 알려줌
-@joinColumn = join할때 사용하는 column은 무엇인지
5)OneToMany bidirectional
@OneToMany (mappedBy = "category", cascade= Cascade=CascadeType.ALL, fetch=FetchType.LAZY
private Set products;
@ManyToOne
@JoinColumn(name="category_id")
private Category category;
-mappedBy : child class에 represent한 parent가 무엇인지One , @OneToMany, @ManyToOne, @ManyToMany
6)direction : bidirectional, unidirectional
7)Entity Relation Attributes
1: CascadeType: 연관된 것도 동일 적용 할 것 인지 //부모쪽에 주로 넣기
ALL, PERSIST,MERGE,REMOVE,REFRESH
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
2: FetchType : 연관된 것도 로드할 것 인지 LAZY=로드 적용 x , EAGER= 로드 동일 적용
@OneToMany, @ManyToMany = FetchType.LAZY
@OneToOne, @ManyToOne= FetchType.EAGER
4)OneToMany Unidirectional
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="category_id")
private Category category
-외래키는 Many(child)쪽에 둘 것 parent=One 쪽, childe= Many쪽
-@ManyToOne =Many 쪽이고 child구나라고 hibernate가 알려줌
-@joinColumn = join할때 사용하는 column은 무엇인지
5)OneToMany bidirectional
@OneToMany (mappedBy = "category", cascade= Cascade=CascadeType.ALL, fetch=FetchType.LAZY
private Set products;
@ManyToOne
@JoinColumn(name="category_id")
private Category category;
-mappedBy : child class에 represent한 parent가 무엇인지
6)OneToOne Unidirectional
외래키 가진 One쪽 -License
@OneToOne(optional =false, cascade=CascadeType.ALL)
@JoinColumn(unique=true, name="person_id")
private Person person;
license.setPerson(person)
7)OneToOne bidirectional
license.setPerson(person);
person.setLicense(license);
8)ManyToMany unidirectional -> jointable 사용
각 테이블의 기본키를 가지는 jointable
@ManyToMany(cascade= CascadeType.ALL
@JoinTable(name ="author_book", joinColumns = {@JoinColumn(name = "book_id")}, inverseJoinColumns = {@JoinColumn(name ="author_id")})
private Set authors;