일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- it
- 맛집
- Web Server
- php
- javascript
- Spring
- AWS
- tool
- elasticsearch
- IntelliJ
- laravel
- jsp
- MySQL
- Oracle
- java
- 요리
- Git
- redis
- db
- springboot
- devops
- ReactJS
- JPA
- Spring Boot
- linux
- docker
- ubuntu
- Design Patterns
- jenkins
- Gradle
Archives
- Today
- Total
아무거나
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails 에러 본문
Java/JPA
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails 에러
전봉근 2018. 9. 12. 16:25반응형
@OneToOne이나 @OneToMany .. 등의 외래키 관계의 데이터를 삭제할 경우에 Foreign key가 지정되어있는 경우
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails ...... FOREIGN KEY ....
라는 에러를 출력한다.
해결방법은 만약 entity의 annotation이 @OneToMany이라고 하면 해당 annotation에 cascade 설정을 추가한다.
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "brand_id")
private List<BrandProduct> brandProduct;
반응형
'Java > JPA' 카테고리의 다른 글
[Spring Boot] JPA DatasourceConfig 설정 (Multi Connection 또는 추가 설정시 유용) (0) | 2021.06.16 |
---|---|
Entity Graph 설명 (0) | 2021.01.16 |
[JPQL] JPQL 기본 사용 예 (0) | 2019.08.23 |
jpql 바인딩 에러 No parameter binding found for name (0) | 2019.03.26 |
javax.persistence.EntityNotFoundException: Unable to find ... with id 0 에러 (0) | 2018.09.12 |
Comments