0
任何人都可以解释为什么会抛出JPQL异常吗?jpql按尺寸排序错误
Query q = em.createQuery("select object(o) from SiteMember as o order by size(o.memberThread) desc");
memberThread refer a list.
任何人都可以解释为什么会抛出JPQL异常吗?jpql按尺寸排序错误
Query q = em.createQuery("select object(o) from SiteMember as o order by size(o.memberThread) desc");
memberThread refer a list.
很可能是因为您使用的JPA实现(也是数据库供应商可能很重要),它没有针对此查询的供应商扩展。根据JPA 2.0以下类型的值可以在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。
我使用Toplink和这段代码工作正常“从MemberThread选择对象(o)作为o其中size(o.replys)='0'order by o.id desc”.any解决方案请吗? – bews99 2012-07-09 07:37:23
那一个是有效的JPQL查询。问题在于ORDER BY与非法价值相结合。很可能只是查询的排序结果很好,至少没有可移植性问题。如果这不是选项,您可以尝试遵循(不保证工作):将'size(o.memberThread)'作为ord'添加到SELECT,按ord排序,并按SiteMember中的字段进行分组。然后它会变得丑陋,因为结果还包含仅用于ORDER BY的属性。 – 2012-07-09 08:04:16
感谢您的详细回复。 :D – bews99 2012-07-09 10:05:05