분류 전체보기 1341

Ch03. 쿼리 메소드 기능 - @Query, 리포지토리 메소드에 쿼리 정의하기

메서드에서 해당 쿼리를 바로 동작시킬 수 있다. 이름이 없는 네임드 쿼리와 동일한 방식으로 동작하기 때문에 애플리케이션 로딩 시점에 오류를 잡을 수 있는 장점이 있다. 참고 실무에서는 메소드 이름으로 쿼리 생성 기능은 파라미터가 증가하면 메서드 이름이 매우 지저분해진다. 따라서 @Query 기능을 자주 사용하게 된다. @Query, 값, DTO 조회하기 하나의 값만 조회할 때 JPA 값 타입( @Embedded )도 이 방식으로 조회할 수 있다. DTO 직접 조회 DTO로 직접 조회를 하므로 JPA의 new 명령어를 사용해야 한다. 생성자가 맞는 DTO가 필요하다(JPA와 동일)

Ch03. 쿼리 메소드 기능 - JPA NamedQuery

JPA Entity에 NamedQuery를 작성한 뒤, JPQL에서 namedQuery를 호출할 수 있다. 네임드 쿼리는 실무에서 잘 사용하지는 않지만 막강한 기능 중 하나인 애플리케이션 로딩 시점에 쿼리를 파싱 하여 오류를 잡아줄 수 있는 기능이 있다. SpringDataJpa @Query 를 생략하고 메서드 이름만으로 Named 쿼리를 호출할 수 있다. 스프링 데이터 JPA는 선언한 "도메인 클래스 + .(점) + 메서드 이름"으로 Named 쿼리를 찾아서 실행 만약 실행할 Named 쿼리가 없으면 메서드 이름으로 쿼리 생성 전략을 사용한다. 필요하면 전략을 변경할 수 있지만 권장하지 않는다. 참고 : https://docs.spring.io/spring-data/jpa/docs/current/ref..

Ch03. 쿼리 메소드 기능 - 메소드 이름으로 쿼리 생성

https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation Index of /spring-data/jpa/docs/current docs.spring.io JPA JPA에서의 커스텀 JPQL이다. username, age를 파라미터로 받아 쿼리를 실행한다. Test SpringDataJpa 스프링 데이터 JPA는 메서드 이름을 분석해서 JPQL을 생성하고 실행 단점 : 조건이 증가할수록 메서드명이 길어진다. 스프링 데이터 JPA가 제공하는 쿼리 메서드 기능 조회: find…By , read…By , query…By get…By COUNT: count…By 반환타입 long EXISTS..

Ch02. 공통 인터페이스 기능 - 공통 인터페이스 분석

JpaRepository를 변경만 하면 DB를 변경할 수 있다. JpaRepository 분석 여러 기능이 있다. package org.springframework.data.jpa.repository; 안에 존재한다. PagingAndSortingRepository, QueryByExampleExecutor 를 상속한다. PagingAndSortingRepository 분석 package org.springframework.data.repository; 안에 존재한다. 페이징은 DB에 상관없이 공통으로 해당 기능을 사용할 수 있다. CrudRepository 를 상속한다. CrudRepository 분석 Repository를 상속한다. 제네릭 타입 T : 엔티티 ID : 엔티티의 식별자 타입 S : 엔티..

Ch02. 공통 인터페이스 기능 - 공통 인터페이스 설정

JavaConfig 설정- 스프링 부트 사용 시 생략 가능 SpringDataJPA가 구현 클래스 대신 생성 개발자가 구현한 것이 없는데 대체 주업되는 것은 무엇일까? System.out.println("memberRepository = "+memberRepository.getClass()); interface를 보고 SpringDataJpa가 만들어 주입시킨다. org.springframework.data.repository.Repository를 구현한 클래스는 스캔 대상 MemberRepository 인터페이스가 동작한 이유 실제 출력해보기(Proxy) memberRepository.getClass() class com.sun.proxy.$ProxyXXX @Repository 애노테이션 생략 가능 컴..

Ch02. 공통 인터페이스 기능 - 순수 JPA 기반 리포지토리 만들기

Spring DATA JPA는 결국 JPA를 알아야지 한계 없이 사용할 수가 있다. MemberJpaRepository 구현 @Repository public class MemberJpaRepository { @PersistenceContext private EntityManager em; public Member save(Member member){ em.persist(member); return member; } public Member find(Long id){ return em.find(Member.class,id); } public void delete(Member member){ em.remove(member); } public List findAll(){ //JPQL return em.cre..

Ch01. 프로젝트 환경 설정 - H2 데이터베이스 설치

https://www.h2database.com/html/main.html H2 Database Engine H2 Database Engine Welcome to H2, the Java SQL database. The main features of H2 are: Very fast, open source, JDBC API Embedded and server modes; in-memory databases Browser based Console application Small footprint: around 2.5 MB jar file size Supp www.h2database.com 클라이언트와 서버의 버전을 맞춰주어야 한다. 버전 확인 방법 https://spring.io/ Spring makes Ja..

Ch01. 프로젝트 환경 설정 - 라이브러리 살펴보기

라이브러리 살펴보기 명령어 : ./gradlew dependencies --configuration compileClasspath 프로젝트 폴더 위치에서 해당 명령어를 실행시키면 의존된 라이브러리를 확인할 수 있다. Spring 라이브러리 spring-boot-starter-web spring-boot-starter-tomcat: 톰캣 (웹서버) spring-webmvc: 스프링 웹 MVC spring-boot-starter-data-jpa spring-boot-starter-aop spring-boot-starter-jdbc HikariCP 커넥션 풀 (부트 2.0 기본) hibernate + JPA: 하이버네이트 + JPA spring-data-jpa: 스프링 데이터 JPA spring-boot-st..