Re: Query selecting relationship field not retuning null (issue 637)
Hi Michael,
The changes look good.
-Tom
Michael Bouschen wrote:
>Hi Tom,
>
>attached you find my changes fixing the query compiler to generate an
>outer join when selecting a relationship field. Here is the
>corresponding glassfish issue:
>https://glassfish.dev.java.net/issues/show_bug.cgi?id=637
>
>The following query:
> SELECT o.customer FROM Order o
>should include null in the query result in case there are orders without
>a customer. This means the generated SQL needs an outer join between the
>order and the customer table.
>
>Some details:
>I changed method SelectNode.applyToQuery to set the useOuterJoin flag in
>the SelectGenerationContext in case a relationship field is selected.
>This code is similar to what method generateExpression already does. The
>same change needs to go into ConstructorNode, because a constructor item
>might be a relationship access expression. The latter change exposed a
>problem in class ReportQueryResult: it runs into NPE in case of a
>relationship field with value null. It does not have mapping metadata,
>so it tries to get the class instance for the constructor lookup from
>the value. I fixed this by retrieving the class instance from the
>ClassDescriptor of the corresponding ReportItem. I did not file a
>separate issue for NPE, because w/o the relationship fix there are no
>null relationship field values in a constructor expression, so the NPE
>does not occur.
>
>I think the handling of select expressions in SelectNode needs to be
>cleaned up. I propose to do this as part of fixing issue 638.
>
>File JPQL-fix637-060509.jar includes the compiler changes. I also added
>two new test cases to a query test class in entity-persistence-tests,
>you find them in the other jar JPQL-fix637-test-060509.jar. Please have
>a look.
>
>Regards Michael
>
>