๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

Spring/Spring Data JPA3

JPQL @Query ์—๋Ÿฌ: For queries with named parameters you need to use provide names for method parameters ๐Ÿ“Ž For queries with named parameters you need to use provide names for method parameters Spring Data JPA์—์„œ ์•„๋ž˜ Entity๋ฅผ ํ†ตํ•ด ์กฐํšŒ๋ฅผ ํ•˜๋ ค๋Š”๋ฐ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. (email์— ๋Œ€ํ•œ ๋ฐ์ดํ„ฐ๋Š” DB์— ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.) import ... @Entity @Builder @NoArgsConstructor @AllArgsConstructor @Getter @ToString public class ClubMember extends BaseEntity { @Id private String email; @Column private String password; @Column private String name; @Column pri.. 2021. 7. 6.
JPA ์—ฐ๊ด€๊ด€๊ณ„ ์˜์†์„ฑ ์ „์ด(CASCADE) - CascadeType ๐Ÿ“Ž JPA ์˜์†์„ฑ ์ „์ด(CASCADE) ์•ˆ๋…•ํ•˜์„ธ์š”! ์ด๋ฒˆ์— ์ •๋ฆฌํ•  ๋‚ด์šฉ์€ JPA์—์„œ ์˜์†์„ฑ ์ „์ด(CASCADE)์™€ ๊ด€๋ จ๋œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์ตœ๊ทผ ๊ฐœ๋ฐœ์„ ์ง„ํ–‰ํ•˜๋ฉฐ ๋‘ ์—ฐ๊ด€๋œ ์—”ํ‹ฐํ‹ฐ์—์„œ save()๋ฅผ ํ•˜๋Š” ๊ณผ์ •์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๊ณ , ์ด๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๊ณผ์ •์—์„œ ์˜์†์„ฑ ์ „์ด(CASCADE)๋ผ๋Š” ๊ฐœ๋…์— ๋Œ€ํ•ด ์•Œ๊ฒŒ ๋˜์—ˆ๊ณ , ์ด๋ฅผ ์ •๋ฆฌํ•˜๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค. ๐Ÿ˜Š (โ€ป ์ž˜๋ชป๋œ ๋‚ด์šฉ์ด ํฌํ•จ๋˜์–ด ์žˆ์„์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž˜๋ชป๋œ ๋ถ€๋ถ„์— ๋Œ€ํ•ด ์ง€์ ํ•ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿ˜‚) ๐ŸŽฏ ์˜์†์„ฑ์ „์ด(CASCADE)๋ž€ ? ๋ถ€๋ชจ ์—”ํ‹ฐํ‹ฐ๊ฐ€ ์˜์†ํ™”๋  ๋•Œ ์ž์‹ ์—”ํ‹ฐํ‹ฐ๋„ ๊ฐ™์ด ์˜์†ํ™”๋˜๊ณ , ๋ถ€๋ชจ ์—”ํ‹ฐํ‹ฐ๊ฐ€ ์‚ญ์ œ๋  ๋•Œ ์ž์‹ ์—”ํ‹ฐํ‹ฐ๋„ ์‚ญ์ œ๋˜๋Š” ๋“ฑ ํŠน์ • ์—”ํ‹ฐํ‹ฐ๋ฅผ ์˜์† ์ƒํƒœ๋กœ ๋งŒ๋“ค ๋•Œ ์—ฐ๊ด€๋œ ์—”ํ‹ฐํ‹ฐ๋„ ํ•จ๊ป˜ ์˜์† ์ƒํƒœ๋กœ ์ „์ด๋˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰, ํŠน์ • ์—”ํ‹ฐํ‹ฐ์— ๋Œ€ํ•ด ํŠน์ •ํ•œ ์ž‘.. 2021. 6. 21.
Spring Data JPA ์ฆ‰์‹œ ๋กœ๋”ฉ(Eager Loading) & ์ง€์—ฐ ๋กœ๋”ฉ(Lazy Loading) ๐Ÿ“Ž JPA - @ManyToOne ์ฆ‰์‹œ ๋กœ๋”ฉ๊ณผ ์ง€์—ฐ ๋กœ๋”ฉ(Eager Loading / Lazy Loading) Spring Data JPA์—์„œ @ManyToOne(N:1)์œผ๋กœ ์—ฐ๊ด€๊ด€๊ณ„๊ฐ€ ์„ค์ •๋˜์–ด ์žˆ๋Š” 2๊ฐœ์˜ Entity๊ฐ€ ์กด์žฌํ•  ๋•Œ, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ์ž…์žฅ์—์„œ ๋ณด๋ฉด join์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์‹ค์ œ @ManyToOne์˜ ๊ฒฝ์šฐ FK์ชฝ์˜ ์—”ํ‹ฐํ‹ฐ๋ฅผ ๊ฐ€์ ธ์˜ฌ ๋•Œ PK์ชฝ์˜ ์—”ํ‹ฐํ‹ฐ๋„ ๊ฐ™์ด ๊ฐ€์ ธ์˜ค๊ฒŒ ๋˜๋Š”๋ฐ์š”, ์ด๋Ÿฌํ•œ ๊ณผ์ •์ด ๊ผญ ํ•„์š”ํ•œ๊ฑด์ง€, ํ•„์š”ํ•˜์ง€ ์•Š๋‹ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ์ฆ‰์‹œ ๋กœ๋”ฉ๊ณผ ์ง€์—ฐ ๋กœ๋”ฉ์— ๋Œ€ํ•ด ์˜ˆ์ œ๋ฅผ ํ†ตํ•ด ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. โŒจ๏ธ Board, Member ์—”ํ‹ฐํ‹ฐ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import .. 2021. 6. 17.
๋ฐ˜์‘ํ˜•