1 Reply Latest reply on Jul 6, 2016 4:31 PM by Cheng Fang

    JPA and EJB writter

    jballesteros Newbie

      Why I dont find any example for an ItemReader using JPA and EJB? It is bad practice read from one database and write in another one?


      I have tried to read data from one table of a database, process it and save the process data in another table. The problem is that the reading process becomes an infinite loop, althought the database have only 100 records. This is the code that i have been using:

      public class EjemploDBReader extends AbstractItemReader {

      public static int COUNT = 0;

      PersonaDao personaDao;
      public List personas;
      public EjemploDBReader() {

      public void open(Serializable checkpoint) throws Exception {
      personas = personaDao.obtenerTodos();

      public Persona readItem() throws Exception {
      try {
      for (Persona persona : personas) {
      return persona;
      } catch (Exception e) {
      throw new Exception(“Error al leer Lista Personas: ” + e);
      return null;



      This is mi job.xml file:


      <?xml version="1.0" encoding="UTF-8"?>

      <job id="funcionalidad1Job" xmlns="http://xmlns.jcp.org/xml/ns/javaee"


        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/jobXML_1_0.xsd"


        <step id="inicializarBatch" next="ejemplo1Step">

        <batchlet ref="ejemploBatchlet"/>


        <step id="ejemplo1Step">

        <chunk checkpoint-policy="custom">

        <reader ref="ejemploDBReader"/>

        <processor ref="ejemploProcessor" />

        <writer ref="ejemploJpaWriterDB"></writer>

        <checkpoint-algorithm ref="algoritmoCheckPoint"/>




        • 1. Re: JPA and EJB writter
          Cheng Fang Master

          looks like your readItem method always returns the first item in personas.  Although your COUNT is incremented, it is not checked against the total number of items during each iteration.


          For this purpose, COUNT should not be static.


          something like:


          if(count < persons.size()) {

               return persons.get(count++);


          return null;