Spring Data JPA

wangjh789·2022년 8월 18일
0

[Spring] 스프링-DB-2

목록 보기
7/21

Spring 과 JPA 사이에 Spring Data JPA가 등장했다.
Spring Data는 반복적이고 자주 사용되는 로직을 대신 제공해주는 기술이다. 그 중 Spring Data Jpa 는 Jpa에 더 특화된 기술이다.

public interface SpringDataJpaRepository extends JpaRepository<Item, Long> {

    List<Item> findByItemNameLike(String itemName);

    List<Item> findByPriceLessThanEqual(Integer price);


    List<Item> findByItemNameLikeAndPriceLessThanEqual(String itemName, Integer price);

    @Query("select i from Item i where i.itemName like :itemName and i.price <= :price")
    List<Item> findItems(@Param("itemName") String itemName, @Param("price") Integer price);
}

이렇게 JpaRepository를 상속받으면 Spring Data Jpa가 프록시 기술을 사용해 구현 클래스를 만들어준다. 그리고 만든 구현 클래스의 인스턴스를 만들어 스프링 빈에 등록한다.

스프링 데이터 JPA는 메서드 이름을 분석해 필요한 JPQL을 만들고 실행하면 JPA가 SQL로 번역해 실행한다.

ext["hibernate.version"] = "5.6.5.Final"

JPA 구현체인 하이버네이트 버전을 낮추는 설정

profile
기록

0개의 댓글