0
Good afternoon,
I need help to make an endpoint in Spring Boot, in the database (Mysql), I have the following query:
SELECT U.NOME, P.DESCRICAO FROM USUARIO_PERMISSAO UP
JOIN USUARIO U ON UP.ID_USUARIO = U.ID
JOIN PERMISSAO P ON UP.ID_PERMISSAO = P.ID
The table Usuario_permission, it is created by the bank, Manytomany of the user table and permission, I would like to know how I make an endpoint that I can bring the result.
As I don’t have this "model", I’m not managing to make the return of the Pository.
I’m trying to do it like this:
@Query(nativeQuery = true, value = "SELECT U.NOME, P.DESCRICAO FROM USUARIO_PERMISSAO UP JOIN USUARIO U ON UP.ID_USUARIO = U.ID JOIN PERMISSAO P ON UP.ID_PERMISSAO = P.ID")
Object findByUsuarioPermissao();
@GetMapping
public Object findUsuarioPermissao() {
return usuarioRepository.findByUsuarioPermissao();
}
But when testing is appearing this error:
"message": "query did not return a unique result: 20; nested exception is javax.persistence.NonUniqueResultException: query did not return a unique result: 20"
Hi, what have you tried to do in terms of code?
– Dherik
do us a favor? edit the question and enter these code from above. Thanks.
– Caio Augusto Papai
According to the error this query is returning a list, it has two ways to solve, making the return a List<Object> or put a LIMIT 1 in the sql query. PS recormendo do the Entity of this table, it is much easier to work, I do not know if the Object will work because n is serializable.
– Lucas Bertollo