JPA76 Querydsl 01 - 프로젝트 만들고 설정하기 build.gradle : 먼저 아래와 같은 의존성을 추가하여 스프링 부트 프로젝트를 만든다. 그리고 아래와 같은 플러그인을 추가해야 한다. id "com.ewerk.gradle.plugins.querydsl" version "1.0.10" buildscript { ext { queryDslVersion = "5.0.0" } } plugins { id 'org.springframework.boot' version '2.6.2' id 'io.spring.dependency-management' version '1.0.11.RELEASE' //querydsl 추가 id "com.ewerk.gradle.plugins.querydsl" version "1.0.10" id 'java' } group = 'stud.. 2022. 1. 15. Data JPA 15 - Projections, 네이티브 쿼리 Projections - 엔티티 대신에 DTO를 편리하게 조회하고 싶을 때 사용 - 전체 엔티티가 아니라 회원 이름만 조회하고 싶다면? 먼저 아래와 같이 인터페이스를 만들고, 조회할 엔티티의 필드를 getter형식으로 지정하면 해당 필드만 선택해서 조회(Projection)한다. public interface UsernameOnly { String getUsername();//getter 형식으로 만든다. } 그리고 리퍼지토리에서 아래와 같이 반환타입을 위에서 만든 인터페이스 타입으로 하면 된다. public interface MemberRepository extends JpaRepository, MemberRepositoryCustom, JpaSpecificationExecutor{ // 다른 메서드 .. 2022. 1. 12. Data JPA 14 - 나머지 기능들 1. Specifications, Query By Example 나머지 기능들은 실제로 사용하기에는 애매한 부분들이 많다. 하여 이러한 기능들이 있다~ 정도로만 편하게 이해해보자. Specifications 스프링 데이터 JPA는 JPA Criteria를 활용하여 Specifications라는 개념을 사용할 수 있도록 지원.(그런데 JPA Criteria를 사용한다는 것은 설계가 잘못된 어플리케이션일 수 있음. 되도록 사용하지 않도록 하자.) Specification을 사용하기 위해서는 아래와 같이 이를 사용할 리퍼티토리에서 JpaSpecification을 extends 해주면 된다. 데이터 JPA Member리퍼지토리에서 이를 extends해보자. //여기 public interface MemberRepository extends JpaRepository, Memb.. 2022. 1. 12. Data JPA 13 - 스프링 데이터 JPA 분석 스프링 데이터 JPA 구현체 분석 - 스프링 데이터 JPA가 제공하는 공통 인터페이스의 구현체 - org.springframework.data.jpa.repository.support.SimpleJpaRepository 스프링 데이터 JPA 구현체인 SimpleJpaRepository의 save 메서드는 아래와 같다. @Repository @Transactional(readOnly = true) public class SimpleJpaRepository ...{ @Transactional public S save(S entity) { if (entityInformation.isNew(entity)) { em.persist(entity); return entity; } else return em.merge.. 2022. 1. 11. 이전 1 2 3 4 5 6 7 8 ··· 19 다음