У моей сущности есть список
@OneToMany(mappedBy = "movie", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@OrderBy("date ASC")
private List<MovieReleaseDateEntity> releaseDates = new ArrayList<>();
Я получаю этот список и хочу передать его для коллекции Set
return this.findMovie(id).getReleaseDates()
.stream()
.peek(System.out::println)
.filter(releaseDate -> releaseDate.getStatus() == DataStatus.ACCEPTED)
.peek(System.out::println)
.map(ServiceUtils::toReleaseDateDto)
.peek(System.out::println)
.collect(Collectors.toSet());
Я добавляю в поток
.peek(System.out::println)
для проверки того, что происходит регулярно
[EL Fine]: sql: 2018-06-04 16:57:48.791--ServerSession(344583521)--Connection(1451502475)--SELECT ID, budget, favorite_count, rating, status, title, type FROM movies WHERE ((ID = ?) AND (status = ?))
bind => [2, ACCEPTED]
[EL Fine]: sql: 2018-06-04 16:57:48.798--ServerSession(344583521)--Connection(579647155)--SELECT ID, dtype, entity_version, reported_for_delete, reported_for_update, status, movie_id, release_date_country, release_date FROM movies_info WHERE ((movie_id = ?) AND (dtype = ?)) ORDER BY release_date ASC
bind => [2, RELEASE_DATE]
MovieReleaseDateEntity(super=MovieInfoEntity(id=6, status=ACCEPTED, reportedForUpdate=false, reportedForDelete=false), date=Thu May 03 00:00:00 CEST 2018, country=POLAND)
MovieReleaseDateEntity(super=MovieInfoEntity(id=6, status=ACCEPTED, reportedForUpdate=false, reportedForDelete=false), date=Thu May 03 00:00:00 CEST 2018, country=POLAND)
{"date":"2018-05-02","country":"POLAND"} // found the first object
MovieReleaseDateEntity(super=MovieInfoEntity(id=5, status=ACCEPTED, reportedForUpdate=false, reportedForDelete=false), date=Sat Jun 02 00:00:00 CEST 2018, country=USA)
MovieReleaseDateEntity(super=MovieInfoEntity(id=5, status=ACCEPTED, reportedForUpdate=false, reportedForDelete=false), date=Sat Jun 02 00:00:00 CEST 2018, country=USA)
{"date":"2018-06-01","country":"USA"} // found the second object
MovieReleaseDateEntity(super=MovieInfoEntity(id=3, status=ACCEPTED, reportedForUpdate=false, reportedForDelete=false), date=Sun Jun 03 00:00:00 CEST 2018, country=USA)
MovieReleaseDateEntity(super=MovieInfoEntity(id=3, status=ACCEPTED, reportedForUpdate=false, reportedForDelete=false), date=Sun Jun 03 00:00:00 CEST 2018, country=USA)
{"date":"2018-06-02","country":"USA"} // found the third object
MovieReleaseDateEntity(super=MovieInfoEntity(id=1004, status=WAITING, reportedForUpdate=false, reportedForDelete=false), date=Mon Jun 04 00:00:00 CEST 2018, country=POLAND)
MovieReleaseDateEntity(super=MovieInfoEntity(id=4, status=ACCEPTED, reportedForUpdate=false, reportedForDelete=false), date=Tue Jun 05 00:00:00 CEST 2018, country=USA)
MovieReleaseDateEntity(super=MovieInfoEntity(id=4, status=ACCEPTED, reportedForUpdate=false, reportedForDelete=false), date=Tue Jun 05 00:00:00 CEST 2018, country=USA)
{"date":"2018-06-04","country":"USA"} // found the fourth object
MovieReleaseDateEntity(super=MovieInfoEntity(id=1005, status=WAITING, reportedForUpdate=false, reportedForDelete=false), date=Tue Jun 05 00:00:00 CEST 2018, country=USA)
2018-06-04 16:57:48.925 DEBUG 2308 --- [nio-8443-exec-9] m.m.a.RequestResponseBodyMethodProcessor : Written [[{"date":"2018-05-02","country":"POLAND"}]] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@590013c7]
И, как вы можете видеть, хотя он отфильтровал 4 объекта, только один первый объект был установлен в коллекцию Set
Written [[{"date":"2018-05-02","country":"POLAND"}]]
MovieReleaseDateEntity расширяет MovieInfoEntity
Почему это происходит?