I have following classes:
public class User {
private int id;
private String name;
private List<Comment> comments;
private List<Address> address;
// getters/setters
}
public class Comment {
private int id;
private String comment;
...
// getters/setters
}
public class Address {
private int id;
private String streetName;
...
// getters/setters
}
And a user mapper:
public class UserMapper implements ResultSetMapper<User> {
@Override
public User map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException {
User user = new User();
user.setId(resultSet.getInt("id"));
user.setName(resultSet.getString("name"));
// user.setComments
// user.setAddresses
return user;
}
}
Problem I'm trying to solve, is how to set comments and addresses to user. Also how would sql query look like for this?
You can this library. It automatically takes care of one to many mappings in JDBI.