Skip to Content
Suffering builds character
아카이브17.JPA13.엔티티 제거

13.엔티티 제거

Entity를 제거하는 작업은 EntityManager.remove(entity)로 수행

Sample.java
manager.remove(book);

1-1. Before tx.commit(flush())

remove(entity) 수행 시, 영속성 컨텍스트에서 해당 엔티티를 제거
→ tx.commit()은 아직 호출하지 않았기 때문에 데이터베이스에서는 아직 제거되지 않음

1-2. After tx.commit(flush())

tx.commit()이 수행되어야 flush()가 호출되면서 DELETE Query가 수행되어 데이터베이스에 적용됨

💡
Tip

flush()

영속성 컨텍스트와 데이터베이스 테이블 간의 동기화 작업 수행

Last updated on