1

It is not duplication of What is a NullPointerException, and how do I fix it?. My question is related to problem with external library so I'm not able to fix it by myself and maybe someone can suggest me a workaround for that.

I'm using Eclipselink 2.5.1.

In some cases when I have relation annotated by @BatchFetch(BatchFetchType.IN) there is NullPointerException in class BatchFetchPolicy in line 247. Unfortunately I was not able to find why in other entities, where the same annotation is used I don't have NPE. The scenario which I execute in unit test is

final CustomerContractEntity contract = customerContractDao.getById(CONTRACT_1000);
contract.setStatus(ProcessState.FINALIZED);
customerContractDao.store(contract);

sft.getItems(TODAY, Direction.EXPORT);

So first I select entity from DB. Then I execute update and store object. The last operation (getItems) executes jpql query and this is the call which causes NPE.

I checked that jpql query selects whole entities: "SELECT product, charge, user... " which cause that eclipse uses query type ReportQuery. In case I select only one entity or only fields of entities then ReadAllQuery type is used which works fine. So in my opinion there must be something wrong with ReportQuery implementation.

Root entity is annotated with:

@Entity
@Table(name = "CUST_PROD_CHARGE")
@Cacheable(false)

Child is annotated with:

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "COST_CODE_ID", insertable = false, updatable = false)
@BatchFetch(BatchFetchType.IN)

Error is throws as below:

Caused by: java.lang.NullPointerException
at org.eclipse.persistence.queries.BatchFetchPolicy.getDataResults(BatchFetchPolicy.java:247)
at org.eclipse.persistence.mappings.ForeignReferenceMapping.extractResultFromBatchQuery(ForeignReferenceMapping.java:559)
at org.eclipse.persistence.internal.indirection.NoIndirectionPolicy.valueFromBatchQuery(NoIndirectionPolicy.java:297)
at org.eclipse.persistence.mappings.ForeignReferenceMapping.batchedValueFromRow(ForeignReferenceMapping.java:275)
at org.eclipse.persistence.mappings.ForeignReferenceMapping.valueFromRow(ForeignReferenceMapping.java:2139)
at org.eclipse.persistence.mappings.ForeignReferenceMapping.buildCloneFromRow(ForeignReferenceMapping.java:336)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildAttributesIntoWorkingCopyClone(ObjectBuilder.java:1996)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildWorkingCopyCloneFromRow(ObjectBuilder.java:2249)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObjectInUnitOfWork(ObjectBuilder.java:847)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:734)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:688)
at org.eclipse.persistence.queries.ReportQueryResult.processItem(ReportQueryResult.java:218)
at org.eclipse.persistence.queries.ReportQueryResult.buildResult(ReportQueryResult.java:144)
at org.eclipse.persistence.queries.ReportQueryResult.<init>(ReportQueryResult.java:79)
at org.eclipse.persistence.queries.ReportQuery.buildObject(ReportQuery.java:594)
at org.eclipse.persistence.queries.ReportQuery.buildObjects(ReportQuery.java:645)
at org.eclipse.persistence.queries.ReportQuery.executeDatabaseQuery(ReportQuery.java:848)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:899)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1127)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:403)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1215)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1793)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1775)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1740)
at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:469)

Does anyone had such problem?

What can be wrong in my Entity annotations?

Community
  • 1
  • 1
  • Can you tell us which line throws the exception? – Lajos Arpad Nov 20 '15 at 13:53
  • What is the query you are executing? The code has changed quite a bit in the latest EclipseLink version, so I recommend you try using the latest released build. 2.6.1 at the moment, and file a bug if it still reproduces. The issue seems that the BatchFetchPolicy on the mapping wasn't properly built when using a report query - the query type used when the JPQL/Criteria query doesn't return a simple entity result. – Chris Nov 20 '15 at 15:17
  • Line which throws exception you can see in stacktrace. In my code it is after I call 'query.getResultList()'. I added information in my question that problem occurs in case ReportQuery is used. In case I will select only some fields (not whole objects) ReadAllQuery is used and it works. – Wujek Samo Zło Nov 23 '15 at 07:52
  • 1
    This is a bug of EclipseLink that happens prior EclipseLink 2.6.0 when your query finds by the Entity id. – Alfredo Osorio Jul 05 '16 at 21:21

0 Answers0