I am creating a custom query in Spring using JDBC to join the tables that are in my Database, but when I check the endpoint in PostMan only the results one table appear. Any insight would be helpful.
This is the query:
@Override
public List <User> getAllUserData(int id){
String sql = """
SELECT *
FROM user u
INNER JOIN vehicle v
ON u.id = v.userId
INNER JOIN home h
on u.id = h.userId
WHERE id = ?
""";
return jdbcTemplate.query(sql, new UserRowMapper(), id );
The Row Mapper:
@Override
public User mapRow(ResultSet rs, int rowNum) throws SQLException{
return new User(
rs.getInt("id"),
rs.getNString("first_name"),
rs.getNString("last_name"),
rs.getNString("email")
);
}
The endpoint result:
{
"id": 1,
"firstName": "Johnnie",
"lastName": "Hicks",
"email": "johnnie@test.com"
}
What I am expecting:
{
"id": 1,
"firstName": "first",
"lastName": "last",
"email": "firstLast@test.com",
vehicle: [{
"make": "nissan",
"model": "pathfinder"
}]
home: [{
"type": "apartment"
}]
}