We’re using Java 6, JPA 2.1, and Hibernate 4.3.6.Final. I have the below code that finds our Organization objects …
final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
final CriteriaQuery<Organization> criteria = builder.createQuery(Organization.class);
final Root<Organization> root = criteria.from(Organization.class);
final CriteriaQuery query = buildCriteriaQuery(builder, criteria, root, country, state, organizationTypes, parentOrg, zipCode);
final TypedQuery<Organization> typedQuery = entityManager.createQuery(query);
if (page != null && pageSize != null)
{
int first = (page - 1) * pageSize;
typedQuery.setFirstResult(first);
typedQuery.setMaxResults(pageSize);
} // if
return typedQuery.getResultList();
These Organization objects are very data-intensive objects. We have a data transfer object, OrganizationDto, which only contains a subset of the fields of Organization. Is there a way to configure the above to populate the OrganizationDto objects instead of the Organization objects? What I would like to avoid is getting the result set and then writing a for loop to go through all of it and create all the data transfer objects. It would be great if the query could somehow just populate these data transfer objects right away.