ํฐ์คํ ๋ฆฌ ๋ทฐ
error log
org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : com.codestates.server.domain.license.licensedate.entity.License.licenseInfo -> com.codestates.server.domain.license.licenseinfo.entity.LicenseInfo; nested exception is java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : com.codestates.server.domain.license.licensedate.entity.License.licenseInfo -> com.codestates.server.domain.license.licenseinfo.entity.LicenseInfo
JPA ์ฐ๊ด๊ด๊ณ ํ
์คํธ์ค ๋ฐ์ํ๋ ์ค๋ฅ๋ก ๋ฐ์ ์ด์ ๋
FK๋ก ์ฌ์ฉ๋๋ ์ปฌ๋ผ๊ฐ์ด ์๋ ์ํ์์ ๋ฐ์ดํฐ๋ฅผ ๋ฃ์ผ๋ ค๋ค ๋ฐ์ํ๋์๋ฌ์ด๋ค.
์๋ฅผ ๋ค์ด Person (id, name) ์ด๋ผ๋ ํ
์ด๋ธ๊ณผ Home (id, address, person_id) ๋ผ๋ ํ
์ด๋ธ ๊ด๊ณ๊ฐ ์์ ๋, Person ๋ฐ์ดํฐ๋ฅผ ๋ฃ์ง ์๊ณ Home ๋ฐ์ดํฐ๋ฅผ ๋ฃ์ผ๋ ค๊ณ ํ๋ค๋ฉด, person_id ๊ฐ์ด ์์ด์ ์๋ฌ๊ฐ ๋ฐ์ํ๊ฒ ๋๋ค.
Person person = new Person("haeyoung");
Home home = new Home("Daejeon", person);
homeRepository.save(home); //person์ id ๊ฐ์ด ์๋ค์ด๊ฐ์์ด์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
ํด๊ฒฐ ๋ฐฉ๋ฒ
JPA์์ ์ฐ๊ด ๊ด๊ณ ๋งคํ์ ํ ๋ ์ฌ์ฉํ๋ @ManyToOne, @OneToOne, @OneToMany ์ด๋
ธํ
์ด์
์ cascade ์ต์
์ ์ค์ ํด์ฃผ์ด์ผํ๋ค.
cascade ๋ "์์์ฑ ์ ์ด" ๋ผ๊ณ ํ๋ ๊ฐ๋
์ธ๋ฐ ํน์ ์ํฐํฐ๋ฅผ ์์ํ ํ ๋ ์ฐ๊ด๋ ์ํฐํฐ๋ ํจ๊ป ์์์ํจ๋ค.
Casecade ์ข ๋ฅ
- ALL
- PERSIST
- REMOVE
- MERGE
- REFERESH
- DETACH
์์ฃผ ์ฌ์ฉ๋๋ ๊ฒ์ ALL๊ณผ PERSIST์ด๋ค. ALL์ ์์ ๋ชจ๋ ์์์ฑ์ด ์ ์ด๋๋ ๊ฒฝ์ฐ์ ์ฌ์ฉ๋๊ณ , PERSIST๋ ์ํฐํฐ๊ฐ ์ ์ฅ๋ ๋๋ง ์ฐ์์ ์ผ๋ก ์ ์ฅ๋๊ฒ ํ๋ ์ต์ ์ด๋ค.
์ธ์ ์ฌ์ฉํ๋ฉด๋๋๊ฐ?
Casecade๋ฅผ ์ธ์ ์ฌ์ฉํ๋ฉด ์ข์๊น? 1:N ์ฐ๊ด๊ด๊ณ๋ฅผ ๊ธฐ์ค์ผ๋ก ์ฐ๊ด๊ด๊ณ์ ์ฃผ์ธ์ ํญ์ N์ ์กด์ฌํ๋ค. ์ฆ N๊ฐ ์๋ 1์ ์ฌ์ฉํ๋ฉด ๋๋๊ฒ์ด๋ค. ์๋ฅผ ๋ค์ด

์์ ๊ด๊ณ์์ Post์ Comment๋ 1:N ๊ด๊ณ์ด๋ค. ์ด๊ฒ์ 2๊ฐ์ง ๊ด์ ์ผ๋ก ์ค๊ณํ ์์๋ค.
- Post๊ฐ ์ฌ๋ผ์ง๋๋ผ๋ Comment๋ ์ ์ง๋๋๊ฒฝ์ฐ
- Post๊ฐ ์ฌ๋ผ์ง๋ฉด Comment๋ ์ฌ๋ผ์ง๋ ๊ฒฝ์ฐ (Casecade ์ ์ฉ)
1 ์ ๊ฒฝ์ฐ์๋ Post์์ฑ์๊ฐ Post๋ฅผ ์ญ์ ํด๋ Comment ์์ฑ์๋ ์์ ์ด ์ผ๋ ๋๊ธ์ ํ์ธํ ์์๋ค.
2 ์ ๊ฒฝ์ฐ์๋ Post์์ฑ์๊ฐ Post๋ฅผ ์ญ์ ํ๊ฒ๋๋ค๋ฉด Comment ์์ฑ์๋ ์์ ์ด ์ผ๋ Comment๋ฅผ ํ์ธํ ์์๋ค. ์ด๋ ๊ฒ ์ค๊ณ๋๋๊ฒฝ์ฐ @OneToMany List<Comment> ์ Casecade
๋ฅผ ๊ฑธ๋ฉด ๋๋๊ฒ์ด๋ค.
- Total
- Today
- Yesterday
- doit์๊ณ ๋ฆฌ์ฆ์ ๋ฌธ
- modifiedAt
- yml ๋ถ๋ฆฌ
- Stream
- ์ฝ๋์คํ ์ด์ธ
- JSP
- Til
- Java
- oracle
- ์ ๋ณด์ฒ๋ฆฌ๊ธฐ์ฌ ์ค๊ธฐ
- error
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- ํ๊ณ
- ๋์ปค
- mapper
- xml
- Spring
- ๋ ์
- mysql ์ค์
- codestates
- ๋ค์ด๋๋ฏนํ๋ก๊ทธ๋๋ฐ
- ์ฐ๋ถํฌ
- pyinstaller ์ค์น
- ์ํฐ๋ ์ฑ๋ฆฐ์ง
- PostgreSQL
- VMware
- sqld
- preproject
- docker
- ๋ฐฑ์ค
| ์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
