This week's book giveaway is in the Open Source Projects forum.
We're giving away four copies of Eclipse Collections Categorically: Level up your programming game and have Donald Raab on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Spring integration: jdbc-outbound-channel-adapter: how to ignore duplicatekey exception?

 
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



When I have some duplicate rows (duplicate item/duplicate primary key), then I have below exception
and the whole process stopped. Meaning, no rows that are after the row which caused exception will be ignored.

ERROR LoggingHandler - org.springframework.integration.MessageHandlingException:
...
Caused by: org.springframework.dao.DuplicateKeyException:
...
Caused by: java.sql.SQLIntegrityConstraintViolationException:

Question:

Is there a way or what option should I use/configure the jdbc outbound-channel-adapter
to skip/ignore the DuplicateKeyException and continue the process.

Something like

 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All exceptions thrown by any channel goes to the Error handling channel. You can either configure a global error channel, or you can specify an error channel specific to a given channel. Look at this for explanation of error handling
 
H Paul
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Read link. Very helpful. And tested below 2 cases. Still have question for CASE 2, (have a scan at CASE 1)

2. There are 2 cases:

CASE 1: "sender and reciever in the same thread" (SYNC)


With the above config, I have a "sender and reciever in the same thread". So I can catch the exception and ignore it
and continue the next row insertion. This is OK but SYNCHRONOUS.



CASE 2: "sender and reciever are NOT in the same thread" (A-SYNC)



With the above config, the sender send a message and go away. Meanwhile, when the receiver insert the rows
and if there is any kind of SQL/database exception related, it throw the exception and STOPPED there. Aborted the whole
process.


The exception is put into the 'errorChannel' either by default OR by custom. This is OK.

What I see is once the exception is put into the 'errorChannel', the whole process is stopped.

Question:
XML-wise: how I can tell Spring Integration, when there is an exception, ignore that row (Spring does via 'errorChannel')
and continue the next rows that follow the exception.
 
You ridiculous clown, did you think you could get away with it? This is my favorite tiny ad!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic