자바/JPA
-
Spring JPA 이론 정리자바/JPA 2022. 3. 16. 20:03
1. JPA에서 가장 중요한 2가지 - 객체와 관계형 데이터베이스 매핑하기(ORM) - 영속성 컨텍스트 2. Entity Manager Factory와 EntityManager - 클라이언트 요청에 따라 EntityManager를 생성하여 DB에 접근하고 트랜잭션 처리를 수행합니다. 3. 영속성 컨텍스트 - 엔티티를 영구 저장하는 환경이라는 뜻. - EntityManager를 통해 1:1로 영속성 컨텍스트에 접근합니다. - EntityManager.persist(entity) 4. 엔티티의 생명주기 - 비영속(new): 영속성 컨텍스트와 전혀 관계가 없는 새로운 상태 - 영속(managed): 영속성 컨텍스트에 관리되는 상태 - 준영속(detached): 영속성 컨텍스트에 저장되었다가 분리된 상태 - 삭..
-
02. Spring Boot JPA 테이블 자동 생성자바/JPA 2022. 3. 16. 18:37
1. 스프링에서 JPA 구동방식 - Persistenc class에서 설정 정보를 읽어서 EntityManagerFactory를 만듭니다. 필요할 때마다 EntityManger를 생성해 작동합니다. - 스프링 부트에서는 JPA를 사용할 때 EntityManagerFactory에 대한 코드를 따로 작성할 필요가 없습니다. - 스프링 부트에서는 JpaRepository을 확장 받는 인터페이스를 생성해서 쉽게 JPA 기능을 사용할 수 있습니다. package com.example.hellojpa; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Reposit..
-
01. Spring Boot 임베디드 DB H2 사용해보기자바/JPA 2022. 3. 16. 17:49
1. 스프링 부트 메이븐 프로젝트 생성 https://start.spring.io 2. pom.xml에 maven 라이브러리 적용 https://mvnrepository.com - h2 - spring-boot-starter-data-jpa - lombok (option) 4.0.0 org.springframework.boot spring-boot-starter-parent 2.6.4 com.example helloJpa 0.0.1-SNAPSHOT war helloJpa helloJpa 11 org.projectlombok lombok 1.18.20 org.springframework.boot spring-boot-starter-data-jpa com.h2database h2 2.1.210 org.spr..