2024/08/02 15

[자바 ORM 표준 JPA 프로그래밍] 10-4. 객체지향 쿼리 언어: QueryDSL (1)

김영한 님의 "자바 ORM 표준 JPA 프로그래밍" 책을 정리한 포스팅 입니다. 1. QueryDSLJava에서 쿼리를 생성할 수 있게 해주는 프레임워크 (오픈소스) 특징타입 안전자바 코드 O (문자열 기반 X)컴파일 시점에 타입 체크 동적 쿼리 생성Fluenct API (Method Chaining)직관적인 쿼리 작성 방식 (Readable) 다양한 지원SQL, JPA, MongoDB, Lucense 2. 시작Q Classmetadata (entity field)entity-based(plugin) querydsl-apt  JPAQuery (or JPAQueryFactory)type-safe querydynamicallypublic class UserRepositoryCustomImpl implemen..

[Spring Data JPA] 3-1. Defining Query Methods (2)

4. Repository Methods Returning Collections or IterablesUsing Streamable as Query Method Return Typeinterface PersonRepository extends Repository { Streamable findByFirstnameContaining(String firstname); Streamable findByLastnameContaining(String lastname);}Streamable result = repository.findByFirstnameContaining("av") .and(repository.findByLastnameContaining("ea"));Streamable비병렬 스트림을 접근할 수 있..

[Spring Data JPA] 3-1. Defining Query Methods (1)

1. Query Lookup Strategies@EnableJpaRepositories (queryLookupStrategy)CREATE_IF_NOT_FOUND (default)선언된 쿼리 -> 쿼리 생성 (메서드 이름 기반) CREATE쿼리 생성메서드 이름 기반 (접두사 제외) USE_DECLARED_QUERY선언된 쿼리를 찾으려 시도 (어노테이션)찾을 수 없으면 예외 발생 (부트스트랩 시점) 2. Query CreationQuery Builder MechanismJPQL Query Creation from method nameinterface PersonRepository extends Repository { // 여러 조건을 사용한 쿼리 List findByEmailAddressAndLastna..

[Spring Data JPA] 3-7. Repository query keywords

1. Supported query method subject keywordsfind…Byread…Byget…Byquery…Bysearch…Bystream…ByGeneral query method - can be used in combination with additional keywordsReturn type: the repository type- Collection, Streamable subtype, result wrapper (Page, GeoResults, store-specific)exists…ByExists projectionReturn type: booleancount…ByCount projectionReturn type: booleandelete…Byremove…ByDelete que..