I'm using spring-batch and the JpaPagingItemReader<T> to read a DB to @Entity.
The entity is correctly specified as type argument T.
Problem: The result set that is returned is not of type T, but an array of objects: Object[]. Each object in that array itself is an Object[] array having the following content: [firstname, lastname, date].
So, the database columns are somehow written as String array, and the entities are returned obviously as String[] array.
The reason for this is my query:
SELECT firstname, lastname, min(date) FROM mytable GROUP BY firstname, lastname;
So the reader maps to a string array. How can I have a mapping to my @Entity, maybe only filled with the fields requested in the select?
My reader definition:
JpaPagingItemReader<MyEntity> reader = new JpaPagingItemReader<>();
reader.setEntityManagerFactory(emf);
reader.setQueryString(QUERY);
@Entity
public class MyEntity {
   private String firstname, lastname;
   private Date date;
   public MyEntity(String firstname, String lastname, Date date) {
       this.firstname = firstname;
       this.lastname = lastname;
       this.date = date;
   }
}
 
     
    