Spring Boot

JPA Queries

JPA queries: method name derivation, @Query with JPQL, native queries, pagination, sorting

30 면접 질문·
Mid-Level
1

What is JPQL?

답변

JPQL (Java Persistence Query Language) is an object-oriented language that queries JPA entities rather than database tables. Unlike native SQL, JPQL uses class and property names, which maintains object abstraction and facilitates portability across different database systems. JPQL should be used by default unless specific SQL features are required.

2

Which annotation allows executing a custom JPQL or SQL query?

답변

@Query annotation allows defining custom queries directly in Spring Data JPA repositories. It can contain JPQL by default or native SQL if the nativeQuery attribute is set to true. This annotation offers more flexibility than query methods derived from method names, especially for complex queries with joins or subqueries.

3

How to bind a method parameter to a @Query?

답변

@Param annotation allows explicitly naming parameters used in @Query queries. This approach is more readable and robust than using indexed positions, especially during code refactoring. The annotation is mandatory for named parameters in JPQL and recommended even for native SQL queries to improve maintainability.

4

In JPQL, which clause allows filtering results?

5

What is the main difference between JPQL and native SQL?

+27 면접 질문

다음 면접을 위해 Spring Boot을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기