0

I ma new to spring batch, I just want to ask how can I retrieve data from multiple rows of result set. I have the following scenario :

  1. There are two different table say employee & payroll.
  2. An employee can have multiple payroll on the basis of some ID.
  3. I have used query select * from emp,pay whem emp.id=pay.id & emp.id = "id".
  4. Now it returns multiple row and I have to create an xml
  5. The xml structure is :

    <EMP>
    ....
    ...
    <Payroll>
    .
    .
    .
    </Payroll>
    <Payroll>
    .
    .
    .
    </Payroll>
    </emp>
    

While using RowMapper I can only create One payroll child but the table may have multiple childs. Please help...

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
Developer
  • 3
  • 2

2 Answers2

0

You need something like a group reader, which is wrapped around your database reader.

I explained this approach in another answer: Spring batch to aggregate values and write single value

Community
  • 1
  • 1
Hansjoerg Wingeier
  • 4,274
  • 4
  • 17
  • 25
0

This use case is exactly why ORM frameworks like Hibernate were created. Consider using HibernateCursorItemReader for your reader and then defining your persistence layer such that you have the following:

@Entity
@Table(name = "emp")
public class Employee {

    @Id
    @Column(name = "emp_id")
    private Long id;

    @OneToMany(mappedBy="employee")
    private Set<Payment> payments = new HashSet<>();

}

@Entity
@Table(name = "pay")
public class Payment {

    @Id
    @Column(name = "pay_id")
    private Long id;

    @ManyToOne
    @JoinColumn(name = "emp_id")
    private Employee employee;

}
Dean Clark
  • 3,770
  • 1
  • 11
  • 26