BackEnd/Java

[Java] EntityNotFountException

모야이거였어 2022. 12. 1. 15:03

EntityNotFountException 이 @ManyToOne 에서 발생했을 때 처리방법

@NotFound(action=NotFoundAction.IGNORE)

위 어노테이션을 추가하면 됨

기본은 ignore이 아닌 Exception

optional=true 옵션은 many에 있는 왜래키 컬럼의 값이 null인 케이스를 지정하고,

notFound는 컬럼의 값이 있지만, pk로 가지는 데이터가 one에 해당하는 테이블에 없는 케이스를 지정해줌

 


출처 : https://fusidic.tistory.com/76

 

JPA - EntityNotFoundException

JPA를 이용해 개발하는 중에 EntityNotFoundException 이 발생했다. @ManyToOne 관계에서 발생한 에러인데 평소에 쓰던 optional=true 옵션을 줘도 해결이 안되었다. 해결방법은 @NotFound(action=NotFoundAction.IGNORE)

fusidic.tistory.com