Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to fetch associated entities eagerly using join fetch.
Spring Boot
String jpql = "SELECT p FROM Product p [1] p.category";
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left join' without 'fetch' does not fetch associations eagerly.
Using 'fetch join' alone is not valid JPQL syntax.
✗ Incorrect
Using 'join fetch' in JPQL tells Hibernate to fetch the associated entity eagerly in one query.
2fill in blank
mediumComplete the JPQL query to fetch orders with their items eagerly.
Spring Boot
String jpql = "SELECT o FROM Order o [1] o.items";
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left join' without 'fetch' only joins but does not fetch eagerly.
Using 'fetch' alone is not valid JPQL syntax.
✗ Incorrect
The 'join fetch' keyword fetches the collection 'items' eagerly with the orders.
3fill in blank
hardFix the error in the JPQL query to fetch customers with their addresses eagerly.
Spring Boot
String jpql = "SELECT c FROM Customer c [1] c.addresses";
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'join fetch' excludes customers without addresses.
Using 'fetch join' is invalid syntax.
✗ Incorrect
Using 'left join fetch' fetches the addresses eagerly and includes customers without addresses.
4fill in blank
hardFill both blanks to create a JPQL query that fetches books with authors eagerly and orders by title.
Spring Boot
String jpql = "SELECT b FROM Book b [1] b.authors ORDER BY b.[2]";
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left join' without fetch does not eagerly load authors.
Ordering by 'name' orders by author name, not book title.
✗ Incorrect
We use 'join fetch' to eagerly load authors and order by the book's title.
5fill in blank
hardFill all three blanks to write a JPQL query fetching employees with departments eagerly and filtering by department name.
Spring Boot
String jpql = "SELECT e FROM Employee e [1] e.department WHERE e.department.[2] = :[3]";
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left join' without fetch does not eagerly load departments.
Using wrong property names causes runtime errors.
✗ Incorrect
We use 'join fetch' to eagerly load departments, filter by department name property 'name', and use parameter 'deptName'.