Question: ```
x = 2

if x < 5:
    print("X is Smaller")

elif x < 10:
    print("X is Medium")

else:
    print("X is Bigger")

print("All Done")

```

OUTPUT:

```
X is Smaller
All Done

```

My question is x = 2 is smaller than 5 as well as 10. Then Why the output is the if statement i.e "X is smaller"??? Why not elif statement i.e "X is Medium" ??

Answer: 
The main root cause of the issue was, we were trying to use two different `ItemWriter` to write the data into the same table and this was causing the Transaction to behave weirdly.

We've implemented `SkipListenets` (considering the fact that use may not often get the garbage or junk data as we're performing the validation at the initial data load.)

Since we’ve implemented **“Spring Batch Skip Technique”** in the Batch jobs, this help us to specify certain exception types and a maximum no. of skipped items and whenever one of those skippable exception is thrown, batch job doesn’t fail but skip that particular item and goes onto the next item. Only when maximum no. of skipped items is reached, batch job will fail. We’ve use skip logic with the **“Fault tolerance”** features of Spring Batch are applied to items in chunk-oriented steps, not to the entire step.

Therefore if Item failed to write at one delegate then it will be considered failed for all other delegates (that item will not be passed to another delegates) and we're fine with it because we're capturing the details in the error log table and from there we can reprocess it as when needed.
A couple things here:

1. **Do not use `@Transactional` with Spring Batch -** Spring Batch manages the transactions for you so using that annotation will cause issues. Do not use it.
2. **Manage the exceptions yourself -** In the scenario you are describing, where you want to call four `ItemWriter` implementations for the same item, but want to skip the exceptions at the delegated `ItemWriter` level, you will need to write your own `CompositeItemWriter` implementation. Spring Batch provides that level of composition (where we delegate to each `ItemWriter` implementation with the same item) out of convenience, but from the framework's perspective it is just a single `ItemWriter`. In order to handle exceptions at the child `ItemWriter` level, you will need to write your own wrapper and manage the exceptions yourself.

**UPDATE:**  

An example implementation of the custom `ItemWriter` I'm referring to (note the code below is untested):

```java
public class MyCompositeItemWriter<T> implements ItemWriter<T> {
      private List<ItemWriter<? super T>> delegates;

    @Override
      public void write(List<? extends T> items) throws Exception {
            for(ItemWriter delegate : delegates) {
               try {
                  delegate.write(items);
               }
               catch (Exception e) {
                  // Do logging/error handling here
               }
            }
    }

    @Override
    public void setDelegates(List<ItemWriter<? super T>> delegates) {
        super.setDelegates(delegates);
        this.delegates = delegates;
    }
}

```