Search code examples
jpaeclipselink

EclipseLink error with batch fetch - NullPointerException


EclipseLink 2.3.0 - same issue on 2.3.2 but stack trace from 2.3.0

Running into an issue where batch fetch and fetch join are not playing nicely with each other. I have a query like

select obj from Parent
   left join fetch obj.elementCollection

with hints eclipselink.batch = obj.oneToMany and eclipselink.batch.type = IN.

in the Parent object, there is an @ElementCollection and a @OneToMany, where the @OneToMany is batch-fetched and the @ElementCollection is joined (batch fetch on it instead seemed to have no effect).

It breaks with the below error; changing the batch type from IN to EXISTS makes it work.

java.lang.NullPointerException
   at org.eclipse.persistence.mappings.OneToOneMapping.extractBatchKeyFromRow(OneToOneMapping.java:624)
   at org.eclipse.persistence.mappings.ForeignReferenceMapping.extractResultFromBatchQuery(ForeignReferenceMapping.java:524)
   at org.eclipse.persistence.internal.indirection.NoIndirectionPolicy.valueFromBatchQuery(NoIndirectionPolicy.java:294)
   at org.eclipse.persistence.mappings.ForeignReferenceMapping.batchedValueFromRow(ForeignReferenceMapping.java:215)

Any ideas - am I doing something wrong or is this a bug?


Solution

  • Please try the 2.4 release, and log a bug if the error still occurs.

    You should be able to batch fetch the element collection as well. If you cannot, please log a bug with a test case.