persistence@glassfish.java.net

Re: Fix NPE when populating the result for an outer fetch join query (issue 2881)

From: Tom Ware <tom.ware_at_oracle.com>
Date: Wed, 23 May 2007 14:26:37 -0400

Hi Michael,

  The fix looks good to me.

-Tom

Michael Bouschen wrote:

> Hi Tom,
>
> attached you find my fix for issue 2881 "LEFT JOIN FETCH causes
> NullPointerException":
> https://glassfish.dev.java.net/issues/show_bug.cgi?id=2881.
>
> The NPE occurs in case the query defines an outer fetch join for a
> OneToOne relationship on the non-owning side. E.g.
> SELECT i FROM Item i LEFT JOIN FETCH i.order
> With the relationship definition in class Item:
> @OneToOne(mappedBy="item")
> public Order getOrder() { ... }
>
> Method buildClone in class ForeignReferenceMapping checks the type of
> the cloned attribute value in order to call the getValue method if it
> is a value holder. This check runs into the NPE, in case the
> attribute value is null. I changed the code to call getValue only if
> the attribute value is not null.
>
> The attached jar includes the fix and a new test case. Please have a
> look. Thanks.
>
> Regards Michael