Terence Gronowski wrote:If nobody answers, I find the solution myself...
If you join two tables and want to display field name form table Customer and field discountCode from table DiscountCode you cannot either use Customer or Discount Code.
One solution is to read results in a List (of type Object). In this List there are Object[] arrays which can be read out:
There is one more solution
Result Classes (Constructor Expressions)
JPA supports wrapping JPQL query results with instances of custom result classes. This is mainly useful for queries with multiple SELECT expressions, where custom result objects can provide an object oriented alternative to representing results as Object[] elements.
The fully qualified name of the result class is specified in a NEW expression, as follows:
This query is identical to the previous query above except that now the result list contains CountryAndCapital instances rather than Object[] elements.
The result class must have a compatible constructor that matches the SELECT result expressions, as follows:
The following code demonstrates running this query:
Any class with a compatible constructor can be used as a result class. It could be a JPA managed class (e.g. an entity class) but it could also be a lightweight 'transfer' class that is only used for collecting and processing query results.