Reputation: 181
Considering the following query:
entityManager.createQuery("SELECT r.firstname, r.lastname, r.address FROM User r", queryResultDTO.class).getResultList;
The problem is that I will have to deal with different queries(selecting different attributes from different entities) and all the results have to be mapped to the same queryResultDTO.class. The QueryResultDTO is built to contain all the attributes the queries might return.
Is it posible to make the queries to always return a list of QueryResultDTO where the objects returned will have the selected attributes true and the unselected ones remain as null?
Upvotes: 1
Views: 825
Reputation: 8383
BTW. It is not the right approach to load entities from database using JPA. The better approach is Java Generic with JPA that will save your lot of code. You need to write a GenericDao class that will responsible for perform CRUD operations.
There are lot of examples in internet. Please see here and here
Upvotes: 2