[英]Specifying columns in jpql select causes casting error
When I specify columns in my jpql/jpa 2.0 query, ie 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...
当我在jpql / jpa 2.0查询中指定列时,即select p.id, p.lastName, p.firstName from Profile p where p.group = :group
我得到以下错误: [Ljava.lang.Object; cannot be cast to com.profs.ws.Profile...
[Ljava.lang.Object; cannot be cast to com.profs.ws.Profile...
Anyone know how to resolve this casting issue? [Ljava.lang.Object; cannot be cast to com.profs.ws.Profile...
任何人都知道如何解决这个投射问题?
The Profile
entity class itself has properties of the following types: String, int, and Collection
. Profile
实体类本身具有以下类型的属性: String, int, and Collection
。 The properties I'm selecting in the query are either of the type String
or int
. 我在查询中选择的属性是String
或int
类型。
When you specify properties of an object, JPA returns the list of Object[]
. 指定对象的属性时,JPA返回Object[]
列表。 You can cast the return value to List<Object[]
instead of List<Profile>
to avoid the ClassCastException
. 您可以将返回值强制转换为List<Object[]
而不是List<Profile>
以避免ClassCastException
。 If you are using Hibernate as JPA provider, you can map the select clause to a new object. 如果您使用Hibernate作为JPA提供程序,则可以将select子句映射到新对象。 See select clause documentation for details. 有关详细信息,请参阅select子句文
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.