흰 스타렉스에서 내가 내리지

[JPA] Spring-data-JPA 의 메소드 이름으로 쿼리 생성 본문

JPA

[JPA] Spring-data-JPA 의 메소드 이름으로 쿼리 생성

주씨. 2024. 4. 25. 21:05
728x90

이메일과 이름으로 회원을 조회하려면 다음과 같은 메소드를 정의하면 된다.

List<Member> findByEmailAndName (String email, String name);

 

메소드를 실행하면 스프링 데이터 JPA 는 메소드 이름을 분석해서 JPQL 을 생성하고 실행한다.

실행된 JPQL : 

select m from Member m where m.email = ?1 and m.name = ?2

 

 

# JPA Query Method 표

 

 

https://docs.spring.io/spring-data/jpa/reference/jpa/query-methods.html

 

JPA Query Methods :: Spring Data JPA

By default, Spring Data JPA uses position-based parameter binding, as described in all the preceding examples. This makes query methods a little error-prone when refactoring regarding the parameter position. To solve this issue, you can use @Param annotati

docs.spring.io