Results 1 to 6 of 6

Thread: JpaPagingItemReader Stale Object Exception

  1. #1
    Join Date
    Jun 2009
    Posts
    26

    Default JpaPagingItemReader Stale Object Exception

    We are having an issue with the JpaPagingItemReader. It seems what we are doing is a pretty simple case. We are using the reader to read x number of records; A processor to modifiy a field in that record; and using the JpaItemWriter to update the data.

    The issue occurs on the next read from the JpaPagingItemReader. The first thing it tries to do is a flush of its persistent context which is stale now.

    Am I using the Writer and Reader in a non normal fashion ( doesn't seem like it )? or am I missing some crucial property?

  2. #2

    Default

    is the processing of a record causing updates to other records from the database that you haven't yet read/processed? That is what stale object smells like to me.

    Is there some way you can keep track of these changes and push them out at the end?

  3. #3
    Join Date
    Jun 2009
    Posts
    26

    Default

    not that I know off. Its pretty much like this

    JpaPagingReader read Object

    Processor = object.setFoo( "bar");

    JpaWriter = object.merge();

    But the initial Item that is read exists in the Persistent Context of the reader, so before it does the next read it tries to do a flush()

  4. #4

    Default

    Okay, I am not too familiar on how Spring Batch deals with JPA so I will have to defer on this one.

  5. #5

    Default

    I was having the same issue.

    The issue is the JpaPagingItemReader.doPageRead(...) flushes the persistance context "before" the read instead of doing it after the read (like the javadoc sugests). So when you update an entity in the page number 1, and second call to this method triggers the stale state exception.

    As a work around I have created my own JpaPagingItemReader that does the flush "after" the read.

    I'll file a bug report too.

  6. #6
    Join Date
    Feb 2013
    Posts
    1

    Default

    I see it is a quite old thread, however I had the same kind of problem using the JpaPagingItemReader which gave me some headache... For information, my current Spring Batch version is 2.1.9.RELEASE.

    As symptoms, I got duplicate entries on many-to-one relationships, or duplicate primary key error on one-to-one relationships, or stale exception when I tried to manage persistence by myself (on the other side of the relationship).

    I tried the same work around as the one explained by anshumanpurohit (ie. moving flush and clear instruction at the end of "doReadPage" method), and fortunately it works

    Did you fill a bug report on the Spring Batch Jira? The only problem with such a patch is that I don't know the side effects :/

    I hope my post would help some of those who have the same symptoms!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •