users@glassfish.java.net

[JPA] NullPointerException ***INSIDE*** TopLink (on DISTINCT clause)

From: <glassfish_at_javadesktop.org>
Date: Thu, 21 Jun 2007 07:52:12 PDT

If I have a query like:

[pre]
    @NamedQuery(name = "someEntity.someQueryName",
                query = "select distinct c.contactTaxpayer " +
                        "from OutletContacts c " +
                        "where c.tinId = :tinId ")
[/pre]

it throws a NullPointerException, if some of the "contactTaxpayer" values in the database are null. Here, the "contactTaxpayer" thingie represents a @ManyToOne association. That is, it represents an entity.

Here's the stack trace in Java SE:

[pre]
Exception in thread "Main Thread" java.lang.NullPointerException:
        at oracle.toplink.essentials.queryframework.ReportQueryResult.processItem(ReportQueryResult.java:224)
        at oracle.toplink.essentials.queryframework.ReportQueryResult.buildResult(ReportQueryResult.java:182)
        at oracle.toplink.essentials.queryframework.ReportQueryResult.<init>(ReportQueryResult.java:98)
        at oracle.toplink.essentials.queryframework.ReportQuery.buildObject(ReportQuery.java:594)
        at oracle.toplink.essentials.queryframework.ReportQuery.buildObjects(ReportQuery.java:643)
        at oracle.toplink.essentials.queryframework.ReportQuery.executeDatabaseQuery(ReportQuery.java:804)
        at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:628)
        at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:692)
        at oracle.toplink.essentials.queryframework.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:746)
        at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2233)
        at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:952)
        at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:924)
        at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:361)
        at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.getResultList(EJBQueryImpl.java:472)
        at test.jpa.TestAsm.runTest(TestAsm.java:374)
        at test.jpa.TestAsm.main(TestAsm.java:385)
[/pre]


If I remove the DISTINCT clause, the query works without exceptions.


Best regards,
Bisser
[Message sent by forum member 'bisser' (bisser)]

http://forums.java.net/jive/thread.jspa?messageID=223272