๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Java

[TIL] 240101 RawJPA๋กœ ๊ฐœ๋ฐœํ•˜๊ธฐ

by studymode 2024. 1. 1.

Entity class ๋งŒ๋“ค๊ธฐ

๐Ÿ”ฝ ์ฃผ๋กœ ์•„๋ž˜ ์ˆœ์„œ์™€ ๊ตฌ์„ฑ์œผ๋กœ ๋งŒ๋“ฆ

-์นผ๋Ÿผ

-์ƒ์„ฑ์ž

-์—ฐ๊ด€๊ด€๊ณ„ ํŽธ์˜ ๋ฉ”์†Œ๋“œ

- ์„œ๋น„์Šค ๋ฉ”์†Œ๋“œ (์™ธ๋ถ€์—์„œ entity์ˆ˜์ •ํ• ๋•Œ ๋“ฑ/ boardUpdate๊ฐ™์€๊ฑฐ )

 

@Entity์—๋„ˆํ…Œ์ด์…˜์ด ๋ถ™์œผ๋ฉด @Column์ด ์ž๋™์œผ๋กœ ๋“ค์–ด๊ฐ„๋‹ค

@Column์—์„œ ํŠน์ • ๋ถ€๋ถ„์„ ์ˆ˜์ •ํ•  ๋•Œ๋งŒ ์—๋„ˆํ…Œ์ด์…˜ ์‚ฌ์šฉ

 

@Enuminated: ๋งคํ•‘ํ•  ๋•Œ ์‚ฌ์šฉ

 

@Embedable: ์ฃผ์†Œ์ฒ˜๋Ÿผ ์‹œ๊ตฐ๊ตฌ ๋‚˜๋ˆŒ๋•Œ ์‚ฌ์šฉ

 

livetemplete

ํ…œํ”Œ๋ฆฟ์„ ๋งŒ๋“ค์–ด ๋‹ค๋ฅธ ํด๋ž˜์Šค์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ๊ฒƒ

setting (command+S) > LiveTemplates

 

 

 

 

๋‹ค๋Œ€๋‹ค ๋งคํ•‘ M:N ๋งคํ•‘

๋ณดํ†ต ์ค‘๊ฐ„ ํ…Œ์ด๋ธ”์„ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉ

 

@ManyToOne

joinColumn์€ many์ชฝ์—์„œ ๊ฐ€์ง

 

 

์˜ˆ์‹œ

board์™€ user๋ฅผ ๋‹ค๋Œ€๋‹ค๋กœ ์—ฐ๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด userBoard๋ผ๋Š” ์ค‘๊ฐ„ํ…Œ์ด๋ธ” ์ƒ์„ฑ

 

UserBoard

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "users_id")
private User user;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "boards_id")
private Board board;

 

 

Board 

@OneToMany
private Set<UserBoard> userBoards = new LinkedHashSet<>();

 

 User๋„ ์œ„์™€ ๊ฐ™์€ ์‹์œผ๋กœ ๋งคํ•‘ํ•ด์ค˜์•ผํ•จ