users@jpa-spec.java.net

[jpa-spec users] Non-entity class: legal as second argument to createNamedQuery()?

From: Laird Nelson <ljnelson_at_gmail.com>
Date: Fri, 1 Feb 2013 15:07:48 -0800

Is it legal to use a non-entity class as the second argument to
EntityManager#createNamedQuery(String,
Class)?

For example, I'd like to do:

final List<Frob> stuff =
em.createNamedQuery("someQueryReturningEntityInstancesOfFrob", Frob.class);


...where Frob.class is not an entity class, but is (let's say) an interface
that entities returned by the named query implement.

The javadocs indicate that this should be legal:

The select list of the query must contain only a single item, which must be
> assignable to the type specified by the resultClass argument.


That also tells me that:

final List<Object[]> stuff =
em.createNamedQuery("someQueryReturningObjectArray", Object[].class);


...is illegal. Why is that? If my named query results (logically
speaking) in List<Object[]>, what is the best signature/method to use?

Thanks,
Laird

-- 
http://about.me/lairdnelson