728x90
๊ณ์ธตํ ๊ตฌ์กฐ ๋งคํํ๊ธฐ
@Entity
@Getter
public class Category {
@Id @GenerateValue
@Column(name = "CATEGORY_ID")
private Long id;
private String name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PARENT_ID")
private Category parent;
@OneToMany(mappedBy = "parent")
private List<Category> child = new ArrayList<>();
}
์ด๋ฆ๋ง ์๊ธฐ ์์ ์ด์ง, ๊ทธ๋ฅ ๋ค๋ฅธ ์ํฐํฐ์ ๋งคํํ๋ ๋๋์ผ๋ก ๋งคํํด์ฃผ๋ฉด ๋ฉ๋๋ค.
์์ฑ๋๋ ํ ์ด๋ธ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
Reference
728x90
'๐๏ธ Spring > JPA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JPA] ์คํ๋ง๋ถํธ ์ฌ์ฉ ์ EntityManagerFactory๋ฅผ ์ฃผ์ ๋ฐ๋ ๋ฐฉ๋ฒ (@PersistenceUnit) (0) | 2021.12.18 |
---|---|
[JPA] ์ํฐํฐ, ํ ์ด๋ธ, ์ปฌ๋ผ๋ช ์์ฑ ์ ๋ต (0) | 2021.12.18 |
[JPA] ํ์น ์กฐ์ธ (0) | 2021.12.18 |
[JPA] JPQL์ ๋ฒํฌ ์ฐ์ฐ (0) | 2021.12.17 |
[JPA] JPQL Named ์ฟผ๋ฆฌ (0) | 2021.12.17 |