Ola , fiz de outra forma, eu criei um construtor no SeriesDTO passando a entidade Series :
public record SeriesDTO(
Long id,
String title,
String yearsDuration,
String durationInMinutes,
Integer totalSeasons,
Double rating,
Integer totalVotes,
CategoryGenre genreSeries,
String actors,
String synopsis,
URL poster
) {
** public SeriesDTO(Series series) {
this(series.getId(), series.getTitle(), series.getYearsDuration(), series.getDurationInMinutes(),
series.getTotalSeasons(), series.getRating(), series.getTotalVotes(), series.getGenreSeries(),
series.getActors(), series.getSynopsis(), series.getPoster());
}**
}
Aterei a propriedade da anotacao @OneToMany para *LAZY*
na classe Series :
@OneToMany(mappedBy = "series", cascade = CascadeType.ALL, fetch = FetchType.**LAZY**)
private List<Episode> episodes = new ArrayList<>();
E chamei o stream , ja instanciando a classe SeriesDTO direto no map na classe SeriesController :
@RestController
public class SeriesController {
@Autowired
SerieRepository serieRepository;
@GetMapping("/series")
public List<SeriesDTO> showSeries() {
List<Series> series = serieRepository.findAll();
List<SeriesDTO> seriesDTOS = series.stream().map(**SeriesDTO::new**).collect(Collectors.toList());
return seriesDTOS;
}
}
Essa abordagem tambem seria valida?