본문 바로가기

오류해결/spring

No EntityManager with actual transaction available for current thread - cannot reliably process 'remove' call

1. 원인

db에서 delete를 수행하는 부분에서 발생한 에러다.

검색 결과 다음과 같은 내용을 찾아볼 수 있었다

The @PersistenceContext annotation has an optional attribute type, which defaults to PersistenceContextType.TRANSACTION. This default is what you need to receive a shared EntityManager proxy. The alternative, PersistenceContextType.EXTENDED, is a completely different affair: This results in a so-called extended EntityManager, which is not thread-safe and hence must not be used in a concurrently accessed component such as a Spring-managed singleton bean. Extended EntityManagers are only supposed to be used in stateful components that, for example, reside in a session, with the lifecycle of the EntityManager not tied to a current transaction but rather being completely up to the application.

[출처] 

https://stackoverflow.com/questions/32269192/spring-no-entitymanager-with-actual-transaction-available-for-current-thread

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/orm.html


2. 해결책

delete를 수행하는 메소드에 @Transactional을 붙여준다.