org.hibernate.event.internal.AbstractFlushingEventListener.prepareEntityFlushes

Getting error someimes,

java.lang.NullPointerException: null
at org.hibernate.event.internal.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:138)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:74)
at org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:44)
at org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1398)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1483)
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1445)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414)
at org.hibernate.query.Query.getResultList(Query.java:146)
at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:129)
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:91)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:136)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:125)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:602)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:590)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy263.findAllByIdIn(Unknown Source)
at sun.reflect.GeneratedMethodAccessor648.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)
at com.xxxxxx.project.aop.tenant.TenantAspect.around(TenantAspect.java:89)
at sun.reflect.GeneratedMethodAccessor470.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy263.findAllByIdIn(Unknown Source)
at com.xxxxxx.project.util.Util.lambda$partitionAndProcessItems$0(Util.java:28)
at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:267)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at com.xxxxxx.project.service.SellingPartService.findAllByIdIn(SellingPartService.java:139)
at com.xxxxxx.project.service.SellingPartService$$FastClassBySpringCGLIB$$569e1600.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
at com.xxxxxx.project.service.SellingPartService$$EnhancerBySpringCGLIB$$967c9cb6.findAllByIdIn(<generated>)
at com.xxxxxx.project.api.pub.service.AutoSubscribeSettingService.initiateAutoSubscription(AutoSubscribeSettingService.java:435)
at com.xxxxxx.project.api.pub.service.AutoSubscribeSettingService.access$400(AutoSubscribeSettingService.java:61)
at com.xxxxxx.project.api.pub.service.AutoSubscribeSettingService$1.doInTransactionWithoutResult(AutoSubscribeSettingService.java:325)
at org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:36)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
at com.xxxxxx.project.api.pub.service.AutoSubscribeSettingService.lambda$createAutoSubscriptionForConsumer$19(AutoSubscribeSettingService.java:321)
at com.xxxxxx.project.service.TenantContext.execute(TenantContext.java:49)
at com.xxxxxx.project.service.TenantContext.execute(TenantContext.java:40)
at com.xxxxxx.project.api.pub.service.AutoSubscribeSettingService.createAutoSubscriptionForConsumer(AutoSubscribeSettingService.java:318)
at com.xxxxxx.project.api.pub.service.AutoSubscribeSettingService.createAutoSubscriptionForConsumer(AutoSubscribeSettingService.java:347)
at com.xxxxxx.project.api.pub.service.AutoSubscribeSettingService$$FastClassBySpringCGLIB$$b537d1cd.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:684)
at com.xxxxxx.project.api.pub.service.AutoSubscribeSettingService$$EnhancerBySpringCGLIB$$6a43183d.createAutoSubscriptionForConsumer(<generated>)
at com.xxxxxx.project.api.pub.integration.vmdevents.m2m.VMS.lambda$null$16(VMS.java:208)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at com.xxxxxx.project.api.pub.integration.vmdevents.m2m.VMS.lambda$processUpdateEvent$17(VMS.java:207)
at java.util.Optional.ifPresent(Optional.java:159)
at com.xxxxxx.project.api.pub.integration.vmdevents.m2m.VMS.processUpdateEvent(VMS.java:201)
at com.xxxxxx.project.api.pub.integration.vmdevents.m2m.VMS.processEvent(VMS.java:177)
at com.xxxxxx.project.api.pub.integration.vmdevents.m2m.VMS.fetchEventsForTenant(VMS.java:163)
at com.xxxxxx.project.api.pub.integration.vmdevents.m2m.VMS.lambda$fetchEventsForTenant$6(VMS.java:78)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at com.xxxxxx.project.api.pub.integration.vmdevents.m2m.VMS.fetchEventsForTenant(VMS.java:69)
at com.xxxxxx.project.api.pub.integration.vmdevents.m2m.VMS$$FastClassBySpringCGLIB$$f83308d1.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
at com.xxxxxx.project.api.pub.integration.vmdevents.m2m.VMS$$EnhancerBySpringCGLIB$$20dd3fc9.fetchEventsForTenant(<generated>)
at com.xxxxxx.project.api.pub.integration.vmdevents.VehicleMasterDataEventBatchJob.lambda$fetchScheduleEvents$0(VehicleMasterDataEventBatchJob.java:44)
at com.xxxxxx.project.api.pub.commerceprocess.util.BatchExecutor.lambda$null$2(BatchExecutor.java:88)
at com.xxxxxx.project.api.pub.integration.BatchJobUtil.executeWithLock(BatchJobUtil.java:72)
at com.xxxxxx.project.api.pub.commerceprocess.util.BatchExecutor.lambda$null$3(BatchExecutor.java:88)
at com.xxxxxx.project.service.TenantContext.execute(TenantContext.java:49)
at com.xxxxxx.project.service.TenantContext.execute(TenantContext.java:40)
at com.xxxxxx.project.api.pub.commerceprocess.util.BatchExecutor.lambda$executeInAllTenantsWithLock$4(BatchExecutor.java:84)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at com.xxxxxx.project.api.pub.commerceprocess.util.BatchExecutor.executeInAllTenantsWithLock(BatchExecutor.java:84)
at com.xxxxxx.project.api.pub.commerceprocess.util.BatchExecutor.executeInAllTenantsWithLock(BatchExecutor.java:78)
at com.xxxxxx.project.api.pub.integration.vmdevents.VehicleMasterDataEventBatchJob.fetchScheduleEvents(VehicleMasterDataEventBatchJob.java:43)
at sun.reflect.GeneratedMethodAccessor516.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)