Announcement Announcement Module
Collapse
No announcement yet.
Exception handling / skippable-exception-classes jpaitemwriter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception handling / skippable-exception-classes jpaitemwriter

    I'm having difficulty in adding an exception to the list of skippable-exception-classes in a jpaitemwriter. I have the situation where I want to skip records that generate a constraint condition. Currently the process stops, which is unacceptable.

    I'm using Spring Batch 2.1.7


    Partial setup:

    <chunk reader="someReader" writer="itemWriter" processor="someProcessor"
    commit-interval="30" skip-limit="1000000">

    <skippable-exception-classes>
    <include class="org.springframework.dao.DataIntegrityViolat ionException" />
    <include class="java.sql.BatchUpdateException" />
    </skippable-exception-classes>

    </chunk>

    .....

    <bean id="itemWriter" class="org.springframework.batch.item.database.Jpa ItemWriter">
    <property name="entityManagerFactory" ref="localEntityManagerFactory" />
    </bean>


    Partial console log:

    Local Exception Stack:
    Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.1.1.v20090430-r4097): org.eclipse.persistence.exceptions.DatabaseExcepti on
    Internal Exception: java.sql.BatchUpdateException: ORA-00001: unique constraint (PP_DEV_JED.CM_UK1) violated

    Error Code: 1
    Query: InsertObjectQuery(CmLine[531f6c3b-96cf-495b-a8f8-a220eec3f36b])
    at org.eclipse.persistence.exceptions.DatabaseExcepti on.sqlException(DatabaseException.java:323)

    I have tried all the exceptions listed in the console listing but none seem to work. As one final test, I tried 'java.lang.exception'. This did skip the exception correctly, but is too generic to be used in production. This was only a test to be sure I was using the skippable-exception-classes correctly.

    I've heard about some exception translation logic that I may be invoking that is translating my exception and thus I do not know what it is when the skippable logic is exectuted. I've looked in the Spring Batch doc and cannot find any reference. But I may be searching on the wrong terms.

    Thanks.

  • #2
    looks like the JpaItemWriter doesn't do any exception translation, so making the first exception of the stack trace (org.eclipse.persistence.exceptions.DatabaseExcept ion?) skippable should work.

    Comment


    • #3
      I have already tired that exception. I have tried all of the exceptions listed in the console log. Still researching.

      Seems that the only reason to use JPA is for the exception translation/mapping. If so one would think that JPA would post the mapping somewhere in the doc. Or at least mention how or where the mapping could be found.

      Comment


      • #4
        did you try javax.persistence.PersistenceException then?

        Comment


        • #5
          that is a fairly generic exception. I'm looking for a more specific exception for the constraint exception.

          I already know that the skippable logic works by testing with the java.lang.exception.

          I'm looking for how the PersistenceExceptionTranslator is implemented. Seems to be some code buried deep.

          Comment


          • #6
            yes, I understand. The point was to narrow the java.lang.Exception and see if you *do* get a JPA exception (to be able to use the PersistenceException hierarchy then).

            Comment


            • #7
              Found the problem. Looks like Eclipse link was eating the exception and creating a more generic javax.persistence.PersistenceException. I don't really like this because this is more of a generic database/persistence exception. I would like for my skip logic to only skip on a constraint exception. But this is as close as it gets.

              Being an old COBOL programmer I've spend days figuring out how to handle a problem that should have taken me 2 min to resolve.

              This is just Nuts! I guess I need an EclipseLink and SpringBatch book for Dummies.. because I just don't see the benefits.

              Comment


              • #8
                Found the problem. Looks like Eclipse link was eating the exception and creating a more generic javax.persistence.PersistenceException. I don't really like this because this is more of a generic database/persistence exception. I would like for my skip logic to only skip on a constraint exception. But this is as close as it gets.
                Yes, there's no exception class in JPA for constraint violation, too bad.

                Being an old COBOL programmer I've spend days figuring out how to handle a problem that should have taken me 2 min to resolve.

                This is just Nuts! I guess I need an EclipseLink and SpringBatch book for Dummies.. because I just don't see the benefits.
                JPA + Spring Batch is quite an explosive combination for the newcomer, a lot happens behind the scenes. Perhaps Spring Batch + good old JDBC is easier to begin with.

                Comment


                • #9
                  I have no choice on the technology that I'm using. Working in a large shop where the technology has been chosen and already used in several apps.

                  Java is a great OOP language and as such for some apps is much better than COBOL. But there is no way that Java can approach the efficiency and stability of COBOL in a true batch situation. It's not Java's fault, just a byproduct of it's design.

                  Comment

                  Working...
                  X