반응형
org.springframework.dao.InvalidDataAccessApiUsageException: No EntityManager with actual transaction available for current thread - cannot reliably process 'remove' call; nested exception is javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'remove' call

 

JpaRepository 사용하여 delete를 하는데 해당 오류가 발생하였다. 

 

JPA에서는 데이터베이스 트랜잭션 내에서 작동한다고 한다. 

 

이렇게 작동하는 JPA는 트랜잭션은 커밋이나 롤백을 하지 않으면 영속성 컨텍스트에만 저장이된다.

(*** 영속성 컨텍스트 : JPA에서 엔티티 객체를 보관 및 관리하는 환경)

 

즉, 데이터베이스에 엔티티 객체가 저장이 되지 않는다.

 

@Transactional 어노테이션을 사용하면  JPA의 트랜잭션을 자동으로 시작하고, 커밋 또는 예외발생시 롤백 등을 수행할 수 있다.

 

그러므로 해당 오류는 delete하는 repository를 호출하는 서비스에서 @Transactional 어노테이션을 추가해주고 서버를 재기동해주니 삭제가 정상적으로 되는것을 확인하였다.

반응형

+ Recent posts