I have a hibernate query that returns a list of notifications. Notifications object has a Set
Notifications:
private BigDecimal id;
private BigDecimal createdBy;
private Date createDate;
private BigDecimal deletedBy;
private BigDecimal deletedDate;
private Set<Boards> notificationBoards = new HashSet<Boards>();
Boards:
private BigDecimal id;
private BigDecimal createdBy;
private Date createDate;
My query gives me a list of Notifications.
I have to filter the Notifications based on board Id. So i need to iterate boards to check for id.
If baords id=10 for example then i add to new list else ignore. So i thought i will form another new list of Notifications with only board id = 10.
Below is my loop
public List<Notifications> getNotificationList(List<Notifications> notification, Users loggedInUserObj){
List<Notifications> notificationLi = new ArrayList<Notifications>();
Set<Boards> boardLi = new HashSet<Boards>();
Boards b = new Boards();
Notifications n = new Notifications();
if(notification != null && notification.size() > 0){
for(Notifications notificationObj : notification){
n = notificationObj;
Set<Boards> notificationBoards = notificationObj.getNotificationBoards();
for(Boards board: notificationBoards){
if(board.getId() == loggedInUserObj.getBoardObj().getId()){
b = board;
}
boardLi.add(b);
}
n.setNotificationBoards(boardLi);
}
notificationLi.add(n);
}
return notificationLi;
}
I am getting only one Notifications instaed of a list(I am expecting 2 Notifications as per data) and boards are always null. Can someone point out whats wrong and a better way of doing the same?