首页 > 解决方案 > hashset returns only two elements

问题描述

I am trying to make spring boot application. I have to receive set of diary day for each user.

So, I have User class where:

@OneToMany(mappedBy = "users", fetch = FetchType.EAGER)
@OnDelete(action = OnDeleteAction.CASCADE)
private Set<DiaryDay> diaryDays = new HashSet<>();

I have Diary Day Mental and DiaryDayPhysics Classes which extend DiaryDay class (inheritance strategy is join table). And in DiaryDay class i have:

 @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "users")
@OnDelete(action = OnDeleteAction.CASCADE)
private User users;

in diarydayphysicsDao and diarydaymentalDAO i have methods for receiving all diary days for each user(they are similar, so only one example):

 public Set findByUserId(Long userId) {
    return (Set) getSession().createQuery("from DiaryDayMental where users.id =:userId").setParameter("userId", userId).stream().collect(Collectors.toSet());
}

I added in both tables 3 examples, but i reveived only first from each:

enter image description here

标签: java

解决方案


推荐阅读