반응형
250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- JavaScript
- Jenkins
- aws
- node
- kubeflow
- Python
- bootstrap
- Kafka
- Flux
- Spring
- Spring Error
- chartjs
- java bigdecimal
- SQL
- codedeploy
- COALESCE
- codebuild
- PostgreSQL
- codedeploy error
- docker
- redis
- AWS CI/CD 구축하기
- codepipeline
- chart.js
- IntelliJ
- 도커
- Airflow
- aws cicd
- VPN
- or some instances in your deployment group are experiencing problems.
Archives
- Today
- Total
Small Asteroid Blog
[JPA] object references an unsaved transient instance - save the transient instance before flushing 본문
백엔드/Spring
[JPA] object references an unsaved transient instance - save the transient instance before flushing
작은소행성☄️ 2022. 12. 2. 18:09728x90
JPA 연관관계 사용 중 아래와 같은 에러가 나왔다.
object references an unsaved transient instance - save the transient instance before flushing
오류 이유
해당 오류가 생기는 이유는 FK 로 사용되는 컬럼값이 없는 상태에서 데이터를 넣으려다보니 생기는 에러인 것이다.
예를 들어 아래와 같은 내용이 있을 때
Member (id, name)
Address (id, address1, member_id)
Member에 데이터를 넣지 않고 Address 에 데이터를 넣으려고 하면 member_id 값이 없어서 에러가 발생하는 것이다.
해결 방법
해결 방법으로는 연관관계를 설정할 때 cascade 옵션을 설정해준다.
cascade = CascadeType.PERSIST
cascade = CascadeType.ALL
해당 부분을 사용하면 Address 를 저장하기 전에 Member 값부터 저장되어서 사용된다.
728x90
반응형