Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can iterate over the results of the native query and set the values on the map using multiple parameters. Here's an example:

Map<String, Integer> map = new HashMap<>();

Query query = entityManager.createNativeQuery("SELECT name, score FROM students");

List<Object[]> results = query.getResultList();

for (Object[] result : results) {
    String name = (String) result[0];
    Integer score = (Integer) result[1];
    map.put(name, score);
}

In the above example, we create a native query to retrieve the name and score of all students. We then execute the query and iterate over the results. For each result, we extract the name and score and set them as key-value pairs in the map.