Engineering Note

[JPA] JPA 동작 방식 본문

Server/JPA ORM

[JPA] JPA 동작 방식

Software Engineer Kim 2025. 9. 8. 18:36

JPA 동작 방식

 

 

 

Entity

- 데이터 베이스 테이블에 대응하는 클래스

-  @Entity 어노테이션이 붙은 클래스는 JPA에서 관리하는 엔티티가 된다.

 

 

Entity Manager Factory

- Entity Manager instence를 관리하는 주체

- 애플리케이션 실행 시 한 개만 만들어지며 사용자로부터 요청이 오면 Entity Manager Factory로 부터 Entity 매니저를 생성한다.

 

 

 

Entity Manager

- Persistence Context(영속성 컨텍스트)에 접근하여 Entity에 대한 데이터베이스 작업을 제공

- 내부적으로 데이터베이스 커넥셔능ㄹ 사용해서 데이터베이스에 접근

 

 

Entity Manger의 메서드

1. find() : Persistence Context에서 Entity를 검색하고, 없을경우 데이터베이스에서 데이터를 찾아 Persistence Context에 저장

2. persist() : Entity를 Persistence Context에 저장

3. remove() : Entity 클래스를 Persistence Context에서 삭제

4. flush() : Persistence Context에 저장된 내용을 데이터베이스에 반영

 

 

 

Persistence Context

- Application과 Database 사이를 연결해주는 중간계층으로 JPA가 Entity를 영구 저장하는 환경으로 Entity Manager를 통해 Persistence Context에 접근한다.

-  버퍼링, 캐싱등으로도 사용

Comments