I am trying to develop a Following Followers functionality in a Spring Boot application. i search for example and I saw this one, which made perfect sense at the beginning:
My User had a ManyToMany relation of following, like this....
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "relation",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "following_id"))
private List<User> following;
I developed my controllers, JSPs and tables and it works great to see which user your are following, but the problem came when I tried to develop the Followers.
User_id Following_id
1 2
1 3
1 4
1 6
2 4
2 6
- User_ID=1 is following user: 2,3,4&6
- User_ID=4 has followers: 1&2
How could I ask that table for the followers of user_id=4?
I thought that I should use a FollowerService and DAO, but I realized that I do not have a bean to use it. The only way I think I can do it is to fetch all the table and start searching for all the appearances of a certain following_id to see with user_id is the follower.
I can not find an easy way to do it. Do you think I should create a bean? How? Thanks