How could I wrap a native sql query into a map using
new map?
I would like to create named native queries and their results should be returned in map collection datasources for use in reports.
I would like to use something like the following example:
Code:
<sql-query name="findPerson">
SELECT new map(p.ID AS id, p.NAME AS name)
FROM PERSON p
</sql-query>
Of course this is a simple example that could be easily done with HQL.
But I have many complex SQL queries already done that I want to migrate to Java using Hibernate.
Now I use something like this:
Code:
<sql-query name="findPerson">
<return-scalar column="id" type="int"/>
<return-scalar column="name" type="string"/>
SELECT new map(p.ID AS id, p.NAME AS name)
FROM PERSON p
</sql-query>
The problem is that I have to iterate over the resulting list to convert each element to a Map and add them to a new list.
So, can I use
new map with native queries? Any other suggestion?