How can you create a custom query method in a Spring Data JPA repository?
- By adding a @NamedQuery annotation to the entity class.
- By extending the CrudRepository interface.
- By using the @CustomQuery annotation.
- By using the @Query annotation with JPQL.
You can create a custom query method in a Spring Data JPA repository by using the @Query annotation with JPQL (Java Persistence Query Language). This allows you to define custom queries in your repository interface. Extending the CrudRepository interface provides basic CRUD operations but doesn't allow you to create custom queries directly. The @NamedQuery annotation is used for predefined queries in the entity class, and there's no @CustomQuery annotation in Spring Data JPA.
Loading...
Related Quiz
- How can you perform integration testing on security configurations in a Spring Boot application to ensure security constraints are met?
- To apply data migration scripts in Spring Boot, you can use tools like _____ or _____.
- When using JSR-303 Bean Validation, where can the validation annotations be placed?
- Which of the following is true regarding the @SpringBootTest annotation when testing Spring Boot applications?
- When implementing caching in Spring Boot, how can you handle cache concurrency?