@SuppressWarnings("unchecked")
    public Collection<Owner> findByLastName(String lastName) {
        // using 'join fetch' because a single query should load both owners and pets
        // using 'left join fetch' because it might happen that an owner does not have pets yet
        Query query = this.em.createQuery("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName");
        query.setParameter("lastName", lastName + "%");
        return query.getResultList();
    }
Important: in the current version of this method, we load Owners with all their Pets and Visits while
we do not need Visits at all and we only need one property from the Pet objects (the 'name' property).
There are some ways to improve it such as:
- creating a Ligtweight class (example here: https://community.jboss.org/wiki/LightweightClass)
- Turning on lazy-loading and using {@link OpenSessionInViewFilter}
src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java