开发者

Specifying columns in jpql select causes casting error

开发者 https://www.devze.com 2023-01-26 06:59 出处:网络
When I specify columns in my jpql/jpa 2.0 query, i.e. select p.id, p.lastName, p.firstName from Profile p where p.group = :group I get the following error: [Ljava.lang.Object; cannot be cast to com.pr

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

The Pro开发者_JS百科file entity class itself has properties of the following types: String, int, and Collection. The properties I'm selecting in the query are either of the type String or int.


When you specify properties of an object, JPA returns the list of Object[]. You can cast the return value to List<Object[] instead of List<Profile> to avoid the ClassCastException. If you are using Hibernate as JPA provider, you can map the select clause to a new object. See select clause documentation for details.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号