Specifying columns in jpql select causes fill error

When I specify the columns in my jpql / jpa 2.0 request, i.e. select p.id, p.lastName, p.firstName from Profile p where p.group = :groupI get the following error: [Ljava.lang.Object; cannot be cast to com.profs.ws.Profile...Does anyone know how to solve this casting problem?

The class itself Profilehas the properties of the following types: String, int, and Collection. The properties that I select in the request are of type Stringor int.

+3
source share
1 answer

When you specify the properties of an object, JPA returns a list Object[]. You can return the return value List<Object[]instead List<Profile>to avoid ClassCastException. If you use Hibernate as a JPA provider, you can map the select clause to the new object. For details, see the description of the choice .

+3
source

Source: https://habr.com/ru/post/1776020/


All Articles