Backend Language/JPA(Spring boot)

Repository์—์„œ findBy ์ž‘์„ฑํ•˜๊ณ , ์ดํ›„์— List๋ฅผ ํ†ตํ•ด ๊ฐ’์„ ๋ชจ๋‘ ๋ถˆ๋Ÿฌ์˜ฌ ๋•Œ ๋ชจ๋“  ๊ฐ’์ด ๋ถˆ๋Ÿฌ์ ธ์˜ค๊ฒŒ ๋œ๋‹ค. ํ•˜์ง€๋งŒ, User์™€ ๊ฐ™์€ ๊ฒฝ์šฐ์—๋Š” ๊ฐœ์ธ ์ •๋ณด๊ฐ€ ๊ฐ™์ด ๋ถˆ๋Ÿฌ์ ธ์˜ค๊ฒŒ ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์–ด์„œ ์ด๋ฅผ ๋ฐฉ์ง€ํ•˜๊ณ ์žํ•œ๋‹ค. ๋ชจ๋“  ๊ฐ’์ด ๋ถˆ๋Ÿฌ์ ธ์˜ค๊ฒŒ ๋˜๋Š” ๊ฒฝ์šฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค. @Getter @Entity @NoArgsConstructor @Table(name="user") public class UserEntity{ @Id @GeneratedValue private Long userIdx; @Column(nullable = false, length = 100) private String nickName; @Column(nullable = false, length = 100) private String user..
Spring boot์—์„œ Entity๋ฅผ ์ƒ์„ฑํ•œ ํ›„, @Setter๋ฅผ ํ†ตํ•ด setter ํ•จ์ˆ˜๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ๋˜๋ฉด ๋‹ค๋ฅธ class์—์„œ๋„ ์ •๋ณด๋ฅผ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๊ธฐ์— ๋ณด์•ˆ์ ์œผ๋กœ๋„ ์ข‹์ง€ ์•Š๋‹ค. (์‚ฌ์šฉ์€ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ, ์ง€์–‘ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.) ๊ทธ๋ ‡๋‹ค๋ฉด @Setter ๋Œ€์‹ ์— ์ •๋ณด๋ฅผ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์–ด๋–ค ๊ฒƒ์„ ์‚ฌ์šฉํ•ด์•ผ ํ• ๊นŒ? @Getter @Entity @NoArgsConstructor @Table(name="user") public class UserEntity{ @Id @GeneratedValue private Long userIdx; @Column(nullable = false, length = 100) private String nickName; @Column(nullable = false, length = 100) p..
๐Ÿ’ปUMC ํ™œ๋™์„ ํ•˜๋ฉด์„œ JPA๋กœ Database DML ์ž‘์—…์„ ํ•˜๋˜ ์ค‘, @Id ์–ด๋…ธํ…Œ์ด์…˜์„ ํ•œ ํด๋ž˜์Šค์— ์—ฌ๋Ÿฌ๊ฐœ๋ฅผ ์ž‘์„ฑํ•˜๋‹ˆ ์˜ค๋ฅ˜๊ฐ€ ๋‚ฌ๋‹ค๐Ÿ˜ฉ ๊ตฌ๊ธ€๋ง ํ•ด๋ณด๋‹ˆ, 2๊ฐœ ์ด์ƒ์˜ composite primary key์—์„œ๋Š” @IdClass ํ˜น์€ @EmbeddedId๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค๊ณ  ํ•œ๋‹ค.....(๋ณต์žกํ•ด ์œผ์œ ๐Ÿ˜‘) ๋‚˜๋Š” ๊ทธ ์ค‘์—์„œ๋„ ๊ทธ๋‚˜๋งˆ ์ข€ ๊ฐ„๋‹จํ•ด๋ณด์˜€๋˜ @EmbeddedId๋ฅผ ์‚ฌ์šฉํ•ด๋ณด๊ณ ์ž ํ•œ๋‹ค..(์ €๋ฒˆ์— ๊ทธ๋ž˜๋„ ๊ณต๋ถ€ ํ•ด๋ด์„œ Embedded ๊ฐœ๋…์„ ์•Œ๊ธฐ์—,,) Course Strong Entity์™€ Section Week Entity๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ณด์ž. Section table์—์„œ๋Š” ์ž์‹ ์„ ๋‚˜ํƒ€๋‚ด๋Š” identifier attribute์™€ Course์˜ PK๊ฐ€ ๋ชจ๋‘ PK๋กœ ์ €์žฅ๋˜๋Š” Composite PK ์ผ ๊ฒƒ์ด๋‹ค. ์ด..
1. ์—ฐ๊ด€๊ด€๊ณ„ ์–ด๋…ธํ…Œ์ด์…˜ -> [์ถœ์ฒ˜] one to one: ์ผ๋Œ€์ผ ๋งคํ•‘ one to many: ์ผ๋Œ€๋‹ค ๋งคํ•‘ many to one: ๋‹ค๋Œ€์ผ ๋งคํ•‘ 2. Many to One Mapping User์™€ OrderLine์ด 1:n์˜ ๊ด€๊ณ„์ด๋ฉด, OrderLine Table์— @ManyToOne ์–ด๋…ธํ…Œ์ด์…˜์„ ์ž‘์„ฑํ•ด์•ผ ํ•œ๋‹ค. @ManyToOne(fetch = FetchType.LAZY) FetchType.EAGER [์ฆ‰์‹œ๋กœ๋”ฉ]๋Š” ์—ฐ๊ด€๋œ ์—”ํ„ฐํ‹ฐ๋ฅผ ๋ฐ”๋กœ ์กฐํšŒํ•œ๋‹ค. ์‹ค์ œ ๊ฐ์ฒด๊ฐ€ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋”๋ผ๋„ ์กฐํšŒ๋ฅผํ•œ๋‹ค. FetchType.LAZY [์ง€์—ฐ๋กœ๋”ฉ]์€ ์‹ค์ œ ์‚ฌ์šฉ ์‹œ์ ์— ์กฐํšŒํ•œ๋‹ค. @JoinColumn(name="FK") ์™ธ๋ž˜ํ‚ค ๋งคํ•‘์‹œ ์‚ฌ์šฉ @ManyToOne(optional =True) : FK๋Š” Null (Total par..
UMC ์•ฑ ๋Ÿฐ์นญ ํ”„๋กœ์ ํŠธ์—์„œ JPA๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ๋กœํ–ˆ๋‹ค. Jdbc๋Š” ์‚ฌ์šฉํ•ด๋ดค์ง€๋งŒ, JPA๋Š” ์ฒ˜์Œ์ด๊ธฐ ๋•Œ๋ฌธ์— ๊ณต๋ถ€ํ•ด๋ณด๊ณ ์ž ํ•œ๋‹ค. (Jdbc ์‚ฌ์šฉ๋ณด๋‹ค, Jpa ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ ์ •๋ง ๊น”๋”ํ•ด๋ณด์˜€๋‹ค. ๊ทผ๋ฐ JPA๊ฐ€ ์ข€ ๋” ์–ด๋ ค์›Œ ๋ณด์—ฌ,,,,,) ์˜ค๋Š˜ ๊ณต๋ถ€ํ•  ๋‚ด์šฉ์€ ๋ฐ”๋กœ, JPA๋กœ Spring boot์— Entity ์ƒ์„ฑํ•˜๊ณ  ๊ด€๊ณ„ ์„ค์ •ํ•˜๋Š” ๊ฒƒ!! 1. JPA: ORM(Object Relational Mapping) Framework ORM์€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๊ฐ€ ์„œ๋กœ ํ˜ธํ™˜๋˜์ง€ ๋˜๋„๋ก ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ€๊ฒฝํ•ด์ฃผ๋Š” ๊ฒƒ์„ ์˜๋ฏธ ๊ฐ€์ƒ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๊ตฌ์ถ•ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ฃผ๋Š” ๊ฒƒ 2. Spring boot ์—์„œ์˜ JPA ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ์—”์ง„ -> H2 Database JPA ์„ค์ • Lombok ์„ค์ • -> JPA ์„ค์ •๋ถ€ํ„ฐ Lo..
chaerlo127
'Backend Language/JPA(Spring boot)' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก