You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by "Cannon, Derry" <de...@epsiia.com> on 2007/09/20 00:37:12 UTC

Query returns right number of results, but they're all null?

Has anyone had an issue with a query finding the right number of hits in
a table, but all of the results returned are null?  I've got a user
table with 304 entries.  If I use the following code, I get the right
number of results returned:
 
    Query query = em.createQuery("SELECT u FROM User u");
    List<User> results = query.getResultList();
    System.out.println("Results size = " + results.size());
 
However, if I try to call the toString() method on each User object, I
get a null for every one of them.  Trying to access the username on a
User object throws a null pointer.
 
To further complicate things, I created an entry with the username
"testUser" in the database.  If I change my query to "SELECT u FROM User
u where u.username = 'testUser'" I get one result returned, just as
expected.  However, trying to assign that single result to a User object
with (User)query.getSingleResult() results in a null as well.
 
Help!
Derry Cannon

Re: Query returns right number of results, but they're all null?

Posted by Patrick Linskey <pl...@gmail.com>.
I've not seen that behavior, no. You don't have a reproducible test
case that you could attach to a JIRA issue, do you?

Also, what happens if you turn on trace-level debugging?

    <property name="openjpa.Log" value="DefaultLevel=TRACE"/>

-Patrick

On 9/19/07, Cannon, Derry <de...@epsiia.com> wrote:
> Has anyone had an issue with a query finding the right number of hits in
> a table, but all of the results returned are null?  I've got a user
> table with 304 entries.  If I use the following code, I get the right
> number of results returned:
>
>     Query query = em.createQuery("SELECT u FROM User u");
>     List<User> results = query.getResultList();
>     System.out.println("Results size = " + results.size());
>
> However, if I try to call the toString() method on each User object, I
> get a null for every one of them.  Trying to access the username on a
> User object throws a null pointer.
>
> To further complicate things, I created an entry with the username
> "testUser" in the database.  If I change my query to "SELECT u FROM User
> u where u.username = 'testUser'" I get one result returned, just as
> expected.  However, trying to assign that single result to a User object
> with (User)query.getSingleResult() results in a null as well.
>
> Help!
> Derry Cannon
>


-- 
Patrick Linskey
202 669 5907