Hi,
I'm using OpenJPA 1.2.1 and I need my query to return a list of field in
some entities. Usually I would use the query function but it returns a list
of entities which is not what I want. For an example this is what I need to
do. I have a "User" entity, which has many data members, rather than my
query return a list of User entities I want it to return some data in each
of the User entities returned by my query, for example in normal SQL I would
write:
Select Name, Age, EmailAddress, Weight from com.mypackage.User were Age > 25
Using OpenJPA I only know I can query like this:
Select u from User where Age > 25
But getResultList() will return a list if User entities, but I only want
specific fields as would be returned by my standard SQL above.
I looked at the NativeQuery docs but it looks like I have to return an
entity again:
Query query = em.createNativeQuery("select Name, Age, EmailAddress, Age
where age>25",User.class)
List <User> results = query.getResultList();
which will return a list of Users
What am I missing here?
Thanks
Chris