0
I’m using the Spring framework and the repositories, and in one of the interfaces of one of these repositories I have, for example, a method like this:
@Query("select extract(month from u.atributo1), coalesce(sum(u.atributo2), 0) from #{#entityName} u where extract(year from u.atributo1) = extract(year from current_date()) group by extract(month from u.atributo1)")
public List<HashMap<Integer, BigDecimal>> getDoisAtributos();
It was created the Service that implements this method of the Repository interface in a function and soon after the Controller instance that Service and calls the method responsible for rescuing the values of the database from the service method that then calls this function of the repository.
But I hoped that in the attribute of the type List
an Array with type attributes appears HashMap
but the attributes appear to be of the type Object
and when I traverse the attributes with a foreach for example or even with a for crash an error saying that it was not possible to cast Object
for HashMap
.
Any solution to this problem?
Thanks, I didn’t know about the
TypedQuery
and your answer leads to links as to the solution I found.– Giancarlo Abel Giulian
Typedquery is one of the resources that help in our development life. I am happy to have helped, even if indirectly.
– Weslley Tavares