Spring Boot

JPA Queries

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

30 domande da colloquio·
Mid-Level
1

What is JPQL?

Risposta

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?

Risposta

@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?

Risposta

@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 domande da colloquio

Padroneggia Spring Boot per il tuo prossimo colloquio

Accedi a tutte le domande, flashcards, test tecnici, esercizi di code review e simulatori di colloquio.

Inizia gratis