0
0
Spring Bootframework~10 mins

@Query for custom JPQL in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a custom JPQL query to find users by their email.

Spring Boot
public interface UserRepository extends JpaRepository<User, Long> {
    @Query("SELECT u FROM User u WHERE u.email = [1]")
    User findByEmail(String email);
}
Drag options to blanks, or click blank then click option'
A:email
B?1
Cemail
D?email
Attempts:
3 left
💡 Hint
Common Mistakes
Using positional parameters like ?1 instead of named parameters.
Omitting the colon before the parameter name.
2fill in blank
medium

Complete the code to write a JPQL query that selects users with age greater than a given value.

Spring Boot
public interface UserRepository extends JpaRepository<User, Long> {
    @Query("SELECT u FROM User u WHERE u.age [1] :age")
    List<User> findUsersOlderThan(int age);
}
Drag options to blanks, or click blank then click option'
A<
B<=
C=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of >.
Using = which would select users with exact age.
3fill in blank
hard

Fix the error in the JPQL query to correctly select users by their last name ignoring case.

Spring Boot
public interface UserRepository extends JpaRepository<User, Long> {
    @Query("SELECT u FROM User u WHERE LOWER(u.lastName) = [1]")
    List<User> findByLastNameIgnoreCase(String lastName);
}
Drag options to blanks, or click blank then click option'
ALOWER(:lastName)
B:lastName.toLowerCase()
ClastName.toLowerCase()
D:lastName
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call Java methods on parameters inside JPQL.
Not using the colon for named parameters.
4fill in blank
hard

Fill both blanks to write a JPQL query that selects users whose first name starts with a given prefix.

Spring Boot
public interface UserRepository extends JpaRepository<User, Long> {
    @Query("SELECT u FROM User u WHERE u.firstName [1] :prefix")
    List<User> findByFirstNameStartingWith([2] prefix);
}
Drag options to blanks, or click blank then click option'
ALIKE
BString
Cint
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using = instead of LIKE for pattern matching.
Using int type for a string prefix parameter.
5fill in blank
hard

Fill all three blanks to write a JPQL query that selects users with age between two values.

Spring Boot
public interface UserRepository extends JpaRepository<User, Long> {
    @Query("SELECT u FROM User u WHERE u.age BETWEEN [1] AND [2]")
    List<User> findUsersBetweenAges([3] minAge, [3] maxAge);
}
Drag options to blanks, or click blank then click option'
A:minAge
B:maxAge
Cint
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting colons before parameter names in JPQL.
Using String type for age parameters.