I need to consult a bank that is already created, populated, and maintained by another application. So I do not have the entities in my project and I did not even want to create them.
I'm using Spring Boot with JPA. Here is an example code:
@PersistenceContext
protected EntityManager manager;
public Map<String, Object> getUsuario(String email, String senha) {
Map<String, Object> parameters = new HashMap<>();
parameters.put("email", email);
parameters.put("senha", senha);
Query query = manager.createNativeQuery(
"SELECT * FROM usuarios WHERE email = :email AND senha = :senha");
preencherParametros(parameters, query);
List<Map<String, Object>> resultList = query.getResultList();
return resultList.get(0);
}
I wanted the result of this query to return me a Map with the name of the column and its value. How to do this?