persistence@glassfish.java.net

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

From: Michael Bouschen <Michael.Bouschen_at_Sun.COM>
Date: Wed, 23 May 2007 16:23:53 +0200

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