mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-04-24 11:22:48 +00:00
Alternative approach with eager fetch
This commit is contained in:
parent
e765e3ffe1
commit
bdcaa85460
2 changed files with 1 additions and 6 deletions
|
@ -18,7 +18,6 @@ package org.springframework.samples.petclinic.owner;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
|
@ -154,13 +153,9 @@ class OwnerController {
|
|||
* @return a ModelMap with the model attributes for the view
|
||||
*/
|
||||
@GetMapping("/owners/{ownerId}")
|
||||
@Transactional
|
||||
public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
|
||||
ModelAndView mav = new ModelAndView("owners/ownerDetails");
|
||||
Owner owner = this.owners.findById(ownerId);
|
||||
for (Pet pet : owner.getPets()) {
|
||||
pet.getVisits().size();
|
||||
}
|
||||
mav.addObject(owner);
|
||||
return mav;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public class Pet extends NamedEntity {
|
|||
@JoinColumn(name = "type_id")
|
||||
private PetType type;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "pet_id")
|
||||
@OrderBy("visit_date ASC")
|
||||
private Set<Visit> visits = new LinkedHashSet<>();
|
||||
|
|
Loading…
Reference in a new issue