해결된 질문
작성
·
382
·
수정됨
0
마지막 강을 들으면서 전체 테스트를 돌려보니 deleteAccount 테스트만 오류가 발생했습니다.
에러 로그를 확인해보니
Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint ["FKDDVHOIEDLDMC0I8PA6JUY4X69: PUBLIC.TRANSACTION_TB FOREIGN KEY(DEPOSIT_ACCOUNT_ID) REFERENCES PUBLIC.ACCOUNT_TB(ID) (CAST(1 AS BIGINT))"; SQL statement:
delete from account_tb where id=? [23503-214]]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint ["FKDDVHOIEDLDMC0I8PA6JUY4X69: PUBLIC.TRANSACTION_TB FOREIGN KEY(DEPOSIT_ACCOUNT_ID) REFERENCES PUBLIC.ACCOUNT_TB(ID) (CAST(1 AS BIGINT))"; SQL statement:
delete from account_tb where id=? [23503-214]]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
at app//org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
account의 delete 쿼리가 실행될 때 transaction_tb의 외래키 때문에 무결성 오류가 발생한 것으로 보입니다.
Transaction 엔티티에서 @ManyToOne 부분에 cascade 설정을 해줘야 할까요?
답변 1
1
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
FK제약조건을 해제해줘야 하는데, 코드가 빠져있네요. 수정해두었습니다.