I am looking at this example of JPQL SELECT and it says that you can return a List<Object[]>:
TypedQuery<Object[]> query = em.createQuery(
"SELECT c.name, c.capital.name FROM Country AS c", Object[].class);
List<Object[]> results = query.getResultList();
for (Object[] result : results) {
System.out.println("Country: " + result[0] + ", Capital: " + result[1]);
}
Now I am doing this because of this:
Because construction of managed entity objects has some overhead, queries that return non entity objects, as the two queries above, are usually more efficient. Such queries are useful mainly for displaying information efficiently. They are less productive with operations that update or delete entity objects, in which managed entity objects are needed.
Now I have similar Entity, except that entity Capital in entity Country can be NULL. When I want to get the List<Object[]>, it does not work properly because it cannot access property name from Capital (as I said Capital can be NULL). I want that if the Capital is NULL, the Object[] should then contain NULL value for that property.
You can use the CASE statement: