'spring boot interface left join return just one record, while it contains many
table(model{m_id,name} and table role_model{id,m_id,name,status}
here there is 3 rows in the model and 1 row in the role_model so it must be like this
1 UserManagement NULL 21 0 1 TEST 1
2 RoleManagement NULL NULL NULL NULL NULL NULL
3 Configurations NULL NULL NULL NULL NULL NULL
this is the interface
@Query(value="SELECT * FROM model as m LEFT JOIN role_model as rm on(m.m_id =rm.m_id)",
nativeQuery = true)
List<Model> ListJoined();
this is the service implementation:
public List<Model> listJoined(){
return repo.ListJoined();
}
in controller rest api
@GetMapping("/test")
public String test(){
return service.listJoined();
}
this is returning only one record
1 UserManagement NULL 21 0 1 TEST 1
Solution 1:[1]
Hi please check this example
String GET_MODEL_LIST = "SELECT * FROM model AS m LEFT JOIN role_model AS rm ON m.m_id =rm.m_id";
@Query(GET_MODEL_LIST)
List<Model> ListJoined();
Please read this article, if you are using jpa without typing a query, you can join through methods. https://www.amitph.com/spring-data-jpa-query-methods/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zaur Farrukhzada |
