본문 바로가기

Spring/JPA4

Entity의 기본속성 @Entity @Entity 객체를 persistence상태로 만들어준다. @Id @Id 자바 필드를 pk로 만들어 준다. @GeneratedValue @GeneratedValue 자동적으로 생성할 번호를 붙여준다. public enum GenerationType { /** * Indicates that the persistence provider must assign * primary keys for the entity using an underlying * database table to ensure uniqueness. */ TABLE, /** * Indicates that the persistence provider must assign * primary keys for the entity usi.. 2022. 6. 5.
JPA Repository JPA Repository란? 데이터를 crud할 수 있도록 기본적인 interface를 제공한다. JPA 다이어그램 구조 Repository @Indexed 어노테이션만 있는 interface이다. Repository를 상속받은 class나 interface에 indexing을 해준다. CrudRepository 기본적인 crud에 관련된 메서드들이 정의되어 있는 interface이다. PagingAndSortingRepository Crud에 Page와 Sort기능을 추가한 interface이다. JpaRepository 상위 Interface의 모든 기능을 포함한다. 2022. 6. 5.
Entity 영속성 컨텍스트 영속성 컨텐스트란 엔티티를 영구 저장하는 환경이라는 뜻이다. 애플리케이션과 데이터베이스 사이에서 객체를 보관하는 가상의 데이터베이스 같은 역할을 한다. 엔티티 매니저를 통해 엔티티를 저장하거나 조회하면 엔티티 매니저는 영속성 컨텍스트에 엔티티를 보관하고 관리한다. 캐시 Request가 와서 데이터를 조회 할 때 Key로 조회한다면 1차캐시를 먼저 찾지만 Key가 아니면 DB에서 새로 조회한다. 1차 캐시에 존재한다면 데이터를 불러오고 없다면 DB를 새로 조회한다. Entity 생명주기 비영속(new/transient) 엔티티 객체를 생성했지만 아직 영속성 컨텍스트에 저장하지 않은 상태를 비영속(new/transient)라 한다. @Autowired @Transient private Use.. 2022. 5. 29.
JPA Programming ORM(Object Relational Mapping)이란? DB와 application간에 데이터 접근 및 조작을 하기 위해서 java object와 DB사이를 mapping해 줄 수 있는 layer가 필요하다. 이 다리 역할을 해주는 것이 Object Relational Mapping, ORM, 이다. Spring Framework는 JPA, Hibernate, DAO와 transaction을 통합하여 관리 할 수 있도록 지원해준다. Spring Framework의 장점 Easier testing. IoC접근은 Hibernate SessionFactory instances, JDBC DataSource instances, transaction managers, and mapped object의 설정과.. 2022. 5. 1.