My "team" endpoint is working fine , I'm getting response from rest client, however I'm not able to retrieve members inside each team.
My Json File looks something like this:
{
"id": 5,
"teamName": "OUTLIERS",
"year": 2021,
"teamLead": {
"name":"bbb",
"status":"ABC"
}, "members":[
{},{},{}
]
Team End Point :
@GetMapping(path = **"/{id}/members")**
public List<Member> getTeamMembers(@PathVariable Long id) {
//System.out.println(team.getMembers().size());
List<Member> members = teamRepo.getOne(id).getMembers();
return members;
}
// ----- Member Pojos ---
package org.itpn.web.pojos;
import lombok.Data;
@Data
public class MemberVO {
private Long memberId;
String firstName;
String lastName;
String membershipId;
Long primaryPhone;
String whatsappPhone;
String emailAddress;
boolean active;
}
In the above code root directory is "/teams" , I'm trying to fetch members from teams/id/members resource.
CodePudding user response:
As by information given so far I suggest to create a method getTeamWithMembers(Long id) in repository with HQL query like this:
select t from Team t left join fetch t.members
CodePudding user response:
try fetch type - eager as fetch = FetchType.EAGER