Code Room
Code reviewMedium
Question
Review this Java (JPA/Hibernate) service method.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
@Transactional(readOnly = true)public List<TeamDto> activeTeams() { List<Team> teams = em.createQuery( "SELECT t FROM Team t WHERE t.active = true", Team.class) .getResultList(); return teams.stream().map(t -> new TeamDto( t.getName(), t.getMembers().size(), // members is @OneToMany(fetch = LAZY) t.getLead().getEmail() // lead is @ManyToOne(fetch = LAZY) )).collect(Collectors.toList());}Run or narrate your approach, then ask the coach.