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?