I am having trouble working out why my foundUser object comes back as null when the correct parameter is being passed to the findByUserName method
Here is where the method is called
public static ObjectNode getAllConnections(String userName){
List<Connections> connectionsUsernames = find.where().eq("username", userName).findList();
Iterator<Connections> connectionsIterator = connectionsUsernames.iterator();
ObjectNode response = Json.newObject();
ObjectNode responseItem = Json.newObject();
while (connectionsIterator.hasNext()){
Connections connection = connectionsIterator.next();
User foundUser = User.findByUserName(connection.connectionUserName);
responseItem.put("jobtitle", foundUser.jobTitle);
responseItem.put("connectionid", connection.connectionId.toString());
responseItem.put("connectionusername", connection.connectionUserName);
responseItem.put("connectiondate", connection.connectionDate);
response.put(connection.connectionUserName, responseItem);
}
return response;
}
It is failing on the line User foundUser = User.findByUserName(connection.connectionUserName);
What I am trying to do is get the details from the database of the user who's userName is stored in the connection.ConnectionUserName variable but the foundUser variable is null even when I can see in debug that a correct String is being passed to the method
Here is the findByUserName method in the User class
public static User findByUserName(String userName) {
return find.where().eq("username", userName).findUnique();
}
Any help would be appreciated, I think I just need a different set of eyes to look over this and see an obvious error that I'm missing!
Thanks in advance!!