Announcement Announcement Module
Collapse
No announcement yet.
EmptyResultDataAccessException and entity id exist Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • EmptyResultDataAccessException and entity id exist

    I use spring data jpa repository inside a spring batch project.
    I try to delete some entities inside a step and sometime i've got this exception :

    org.springframework.dao.EmptyResultDataAccessExcep tion: No class com.company.domain.MyEntity entity with id (my_id) exists!

    I don't understand why this exception is thrown because my record exist in the database.

    Do you think if it's a problem with cache or the status of my table (innodb)?

    Thanks in advance.

  • #2
    This is an interesting question. As there are two different projects working together. Is it a Spring Data issue or a Spring Batch issue.

    For me there are some questions that I would ask in regards to the Spring Batch portion.
    1) What is your chunk size.
    2) Where do you do your delete, is it in a reader, writer, or processor? This can make a big difference when you consider the transaction demarcation.
    3) How are the ids retrieved, is this what the reader gets first.
    4) Is your batch job running in concurrent threads? Maybe one thread deletes it before the other tries and isolation issues or other issues.

    Also, have you written any integration tests testing your repository to make sure first that that works on its own. To isolate Spring Data JPA from Spring Batch.

    The EmptyResultDataAccessException is translated from the actual JPA exception. What does the full stack trace say? What is the root cause of the exception. Might tell us some more.

    Mark

    Comment


    • #3
      First of all, in order to explain how my spring batch application work.

      I retrieve some data from a database (datasource1) with a JdbcPagingItemReader which are mapped in a POJO
      and i use a writer which call my service layer which make the job.
      In my case, i purge some data from an another database based on information from the mapped POJO (datasource2)


      Originally posted by bytor99999 View Post
      1) What is your chunk size.
      The chunk size is configurable in the line command with a parameter.

      Code:
      <step id="myStep">
       <tasklet>
        <chunk reader="readerDatasource1" writer="writerDatasource2" commit-interval="#jobParameters['commit.interval']}" />
         </tasklet>
      </step>
      Originally posted by bytor99999 View Post
      2) Where do you do your delete, is it in a reader, writer, or processor? This can make a big difference when you consider the transaction demarcation.
      In the writer due to a service layer.
      Each datasource has its own transaction manager


      Originally posted by bytor99999 View Post
      3) How are the ids retrieved, is this what the reader gets first.
      The reader make a Jdbc query mapped into a POJO (a sort of SQL view).

      Originally posted by bytor99999 View Post
      4) Is your batch job running in concurrent threads? Maybe one thread deletes it before the other tries and isolation issues or other issues.
      I dont know all the recommendation to use properly Spring Batch, i have no idea if my job runned concurrent thread. I have only a job with 2 steps.

      The first one check if some data are OK.
      The second do the job.

      Originally posted by bytor99999 View Post
      Also, have you written any integration tests testing your repository to make sure first that that works on its own. To isolate Spring Data JPA from Spring Batch.
      The unit test with my service layer which contains the Spring Data JPA framework indicate that everything work.

      Comment


      • #4
        Originally posted by bytor99999 View Post
        The EmptyResultDataAccessException is translated from the actual JPA exception. What does the full stack trace say? What is the root cause of the exception. Might tell us some more.
        Code:
        10:39:00.725|I|ArchivingService                        |Purge de l'instance 'my_id' avec la revision '12' pour le partenaire 'MY_PARTNER' ...
        10:39:00.725|I|ArchivingService                        |L'instance '12' de la carte 'my_id' est eligible pour une purge...
        10:39:00.728|I|ArchivingService                        |Suppression de l'enregistrement 'MY_PARTNER:my_id:12 ...
        10:39:00.745|I|ArchivingService                        |Suppression de la carte 'my_id' ainsi que des données associées ...
        10:39:00.773|E|AbstractStep                            |Encountered an error executing the step
        org.springframework.dao.EmptyResultDataAccessException: No class com.company.service.cardstore.domain.MyEntity entity with id my_id exists!
        	at org.springframework.data.jpa.repository.support.SimpleJpaRepository.delete(SimpleJpaRepository.java:127) ~[spring-data-jpa-1.2.0.RELEASE.jar:na]
        	at sun.reflect.GeneratedMethodAccessor43.invoke(Unknown Source) ~[na:na]
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_05]
        	at java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0_05]
        	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:334) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
        	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:319) ~[spring-data-commons-core-1.4.0.RELEASE.jar:na]
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) ~[spring-tx-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155) ~[spring-tx-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:84) ~[spring-data-jpa-1.2.0.RELEASE.jar:na]
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at $Proxy39.delete(Unknown Source) ~[na:na]
        	at com.company.batch.cardstore.job.archiving.dal.service.ArchivingServiceImpl.doPurge(ArchivingServiceImpl.java:212) ~[cardstore-operations-1.0.0-SNAPSHOT.jar:na]
        	at com.company.batch.cardstore.job.archiving.CardInstancePurgeWriter.write(CardInstancePurgeWriter.java:23) ~[cardstore-operations-1.0.0-SNAPSHOT.jar:na]
        	at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source) ~[na:na]
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_05]
        	at java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0_05]
        	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at $Proxy11.write(Unknown Source) ~[na:na]
        	at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:174) ~[spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:150) ~[spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:272) ~[spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:197) ~[spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:74) ~[spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:386) ~[spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130) ~[spring-tx-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:264) ~[spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76) ~[spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367) ~[spring-batch-infrastructure-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214) ~[spring-batch-infrastructure-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143) ~[spring-batch-infrastructure-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:250) ~[spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195) ~[spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135) [spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61) [spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60) [spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144) [spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124) [spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135) [spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:293) [spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120) [spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48) [spring-core-3.2.0.RELEASE.jar:3.2.0.RELEASE]
        	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114) [spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:349) [spring-batch-core-2.1.9.RELEASE.jar:na]
        	at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574) [spring-batch-core-2.1.9.RELEASE.jar:na]
        10:39:00.786|I|SimpleJobLauncher                       |Job: [FlowJob: [name=purgeInstanceJob]] completed with the following parameters: [{commit.interval=100, sequence.number=1}] and the following status: [FAILED]

        Comment

        Working...
        X