persistence@glassfish.java.net

Result of a native query with SqlResultSetMapping

From: Michael Bouschen <Michael.Bouschen_at_Sun.COM>
Date: Mon, 06 Feb 2006 16:39:51 +0100

Hi Linda, hi Mike,

I was looking in one of the question raised in the glassfish forum:
http://forums.java.net/jive/thread.jspa?threadID=2667&tstart=0

The question is about the result returned by Query.getResultList for a
native query using a SqlResultSetMapping. I understand that the query
returns a list of arrays if the SqlResultSetMapping specifies multiple
entity types. But does it still use an array as the list element in case
there is only a single entity type? Or does the query return a list of
entities? The user posting the forum question is expecting the latter
which sounds reasonable to me.

Here is a simple example:
   @SqlResultSetMapping(name="simpleCustomerMapping",
     entities={_at_EntityResult(entityClass=ejbql.models.Customer.class)})
   Query q = em.createNativeQuery(
     "SELECT ID, VERSION, CITY, NAME FROM CUSTOMER_TABLE WHERE ID=1",
     "simpleCustomerMapping");
Does query.getResultList() return List<Customer[]> or List<Customer>?

What do you think?

Regards Michael