From 842f9ac9ec6b28172d6bcfd6469fa39bcdd2504e Mon Sep 17 00:00:00 2001
From: Mic <misvy@vmware.com>
Date: Mon, 11 Mar 2013 09:22:01 +0800
Subject: [PATCH] added comments about OSIV

---
 .../petclinic/repository/jpa/JpaOwnerRepositoryImpl.java | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java
index acebc63..426f711 100644
--- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java
+++ b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java
@@ -15,6 +15,7 @@
  */
 package org.springframework.samples.petclinic.repository.jpa;
 
+import org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;
 import org.springframework.samples.petclinic.model.Owner;
 import org.springframework.samples.petclinic.repository.OwnerRepository;
 import org.springframework.stereotype.Repository;
@@ -40,7 +41,13 @@ public class JpaOwnerRepositoryImpl implements OwnerRepository {
     private EntityManager em;
 
 
-    @Override
+    /**
+     * 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}
+     */
     @SuppressWarnings("unchecked")
     public Collection<Owner> findByLastName(String lastName) {
         // using 'join fetch' because a single query should load both owners and pets
-- 
GitLab