I am trying to select specific fields using Spring Data JPA and JPQL like below:
String query = "Select exampleId, exampleNumber, exampleDate FROM Example Where exampleCost>'209879' And exampleDate BETWEEN '2010-11-17' AND '2018-01-10'";
Query q = entityManager.createQuery(query).setMaxResults(limit);
List<Example> permitList = q.getResultList();
Its returning List of Object Array instead of List of Example. Please note that select fields are differs as per the client needs.
When I checked in SO, I came to know that we need to create CustomObject and multiple constructors for all selected fields.
JPA Query selecting only specific columns without using Criteria Query?
Is there any alternative to achieve my requirement ?