Labs
-
Create a file JPQLRelationshipsLab in the
com.example.jpavideostore.clientpackage. -
Create a file JPQLRelationshipsTests in the
testsrc folder, and configure it as a JUnit test file. -
Write a method in the JPQLRelationshipsLab class named
public List<Store> getStoresByState(String state). -
The method takes a single String as an argument (state).
-
Return a list of stores.
-
Write a test in your
JPQLRelationshipsTeststo ensure that your method is working.- Query for the state of "Washington".
-
Write a method
public List<Rental> getRentalsForCustomerWithCustomerId(int id). -
The method takes a single int as an argument (id).
-
Return a list of rentals associated with the customer of the provided id.
-
NOTE: The list of rentals is lazily initialized by default, instead of eagerly fetching the list, so use a
JOIN FETCH. -
Write a test to ensure that the rentals are retrieved (and that the correct number of rentals are retrieved).
-
Write a method
public List<Film> getFilmsForActorWithId(int id).-
Return the list of films associated with that actor.
-
Write a test to ensure your new method is working.
-
NOTE: The list of films is lazily initialized by default, instead of eagerly fetching the list, so use a
JOIN FETCH.
-
-
Write a method
public int getNumberOfFilmsForCategoryWithName(String name). -
The method should return how many Films are in a certain Category.
-
Note: You can call
.size()on the result from the query to solve this. Don't bother using aCOUNT. This is giving you additional experience withJOIN FETCHin JPQL, rather than writing SQL aggregate queries. -
Write a test to ensure your new method is working. Call your method using the
Comedycategory name.