Skip to content

Commit bdcaa85

Browse files
author
Dave Syer
committed
Alternative approach with eager fetch
1 parent e765e3f commit bdcaa85

File tree

2 files changed

+1
-6
lines changed

2 files changed

+1
-6
lines changed

src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.List;
1919
import java.util.Map;
2020

21-
import javax.transaction.Transactional;
2221
import javax.validation.Valid;
2322

2423
import org.springframework.data.domain.Page;
@@ -154,13 +153,9 @@ public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result,
154153
* @return a ModelMap with the model attributes for the view
155154
*/
156155
@GetMapping("/owners/{ownerId}")
157-
@Transactional
158156
public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
159157
ModelAndView mav = new ModelAndView("owners/ownerDetails");
160158
Owner owner = this.owners.findById(ownerId);
161-
for (Pet pet : owner.getPets()) {
162-
pet.getVisits().size();
163-
}
164159
mav.addObject(owner);
165160
return mav;
166161
}

src/main/java/org/springframework/samples/petclinic/owner/Pet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class Pet extends NamedEntity {
5252
@JoinColumn(name = "type_id")
5353
private PetType type;
5454

55-
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
55+
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
5656
@JoinColumn(name = "pet_id")
5757
@OrderBy("visit_date ASC")
5858
private Set<Visit> visits = new LinkedHashSet<>();

0 commit comments

Comments
 (0)