Labs

  1. Create a file JPQLRelationshipsLab in the com.example.jpavideostore.client package.

  2. Create a file JPQLRelationshipsTests in the test src folder, and configure it as a JUnit test file.

  3. Write a method in the JPQLRelationshipsLab class named public List<Store> getStoresByState(String state).

  4. The method takes a single String as an argument (state).

  5. Return a list of stores.

  6. Write a test in your JPQLRelationshipsTests to ensure that your method is working.

    • Query for the state of "Washington".
  7. Write a method public List<Rental> getRentalsForCustomerWithCustomerId(int id).

  8. The method takes a single int as an argument (id).

  9. Return a list of rentals associated with the customer of the provided id.

  10. NOTE: The list of rentals is lazily initialized by default, instead of eagerly fetching the list, so use a JOIN FETCH.

  11. Write a test to ensure that the rentals are retrieved (and that the correct number of rentals are retrieved).

  12. 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.

  13. Write a method public int getNumberOfFilmsForCategoryWithName(String name).

  14. The method should return how many Films are in a certain Category.

  15. Note: You can call .size() on the result from the query to solve this. Don't bother using a COUNT. This is giving you additional experience with JOIN FETCH in JPQL, rather than writing SQL aggregate queries.

  16. Write a test to ensure your new method is working. Call your method using the Comedy category name.


Prev -- Up