0

谁能解释为什么这会引发 JPQL 异常?

Query q = em.createQuery("select object(o) from SiteMember as o order by size(o.memberThread) desc");

memberThread refer a list.
4

1 回答 1

0

很可能是因为您使用了 JPA 实现(数据库供应商也很重要),它没有针对此类查询的供应商扩展。根据 JPA 2.0,以下类型的值可以使用 in ORDER BY

 1.A state_field_path_expression that evaluates to an orderable state field of an 
   entity or embeddable class abstract schema type designated in the SELECT clause 
   by one of the following:  
 • a general_identification_variable  
 • a single_valued_object_path_expression  

 2.A state_field_path_expression that evaluates to the same state field of the same 
  entity or embeddable abstract schema type as a state_field_path_expression in the
  SELECT clause

3.A result_variable that refers to an orderable item in the SELECT clause for which 
 the same result_variable has been specified. This may be the result of an
 aggregate_expression, a  scalar_expression, or a state_field_path_expression in the 
 SELECT clause.

例如,您的查询适用于 EclipseLink(2.3.2) 和 MySQL。

于 2012-07-09T07:28:48.810 回答