Category: JPA 프로그래밍(기본편)

0

JPA - Persist Context (영속성 컨텍스트)

목차 JPA - Entity의 생명주기 JPA - Persist Context (영속성 컨텍스트) Persist Context (영속성 컨텍스트) 란? JPA 가 Entity 를 관리하기 위한 공간, Entity 상태가 Database 에 반영되기 전까지 Entity 의 읽기/쓰기/수정/삭제를 상태 관리한다. EntityManagerFactory 에서 EntityManager 를 생성하고 EntityManager 를 이용해 영속성 컨텍스트에 접근할 수 있다. EntityManager 를 이용해 Entity(데이터)를 저장하거나 조회하면 영속성 컨텍스트에서 해당 Entity 를 관리하게 된다. EntityManager 는 Transaction 단위로 영속성 컨텍스트를 생성하고 지운다. EntityManager 와 영속성 Context가 1:1로 대응이 된다. 영속성 Context는 내부에 1차 cache가 존재하고 (key, value) 형태로 데이터를 관리한다.장점 : buffering이나 Caching을 할 수 있다. @Id Entity Member1 member @Id : Key Entity : 객체 영속성 컨텍스트의 이점