Jpa EclipseLink在使用选择时引发JPQLException。。。在构造函数表达式中
我有一个带有构造函数表达式的JPQL查询,使用的是EclipseLink 2.7.5 它失败于:Jpa EclipseLink在使用选择时引发JPQLException。。。在构造函数表达式中,jpa,eclipselink,jpql,jpa-2.1,jpa-2.2,Jpa,Eclipselink,Jpql,Jpa 2.1,Jpa 2.2,我有一个带有构造函数表达式的JPQL查询,使用的是EclipseLink 2.7.5 它失败于: Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.7.5.v20191016-ea124dd158): org.eclipse.persistence.exceptions.JPQLException Exception Description: Syntax error parsing [
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.7.5.v20191016-ea124dd158): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing [
SELECT NEW net.bbstats.dto.PlayerStatDto(
gl.playerId,
gl.seasonStartYear,
gl.lastName,
gl.firstName,
gl.incognito,
COUNT(DISTINCT gl.gameId) AS games,
SUM(CASE WHEN gl.hasPlayed = FALSE THEN 1 ELSE 0 END) AS gamesplayed,
SUM(CASE WHEN gl.starter = TRUE THEN 1 ELSE 0 END) AS gamesstarted,
SUM(gl.threePointersMade),
SUM(gl.freeThrowsMade),
SUM(gl.freeThrowsAttempted),
SUM(gl.personalFouls),
SUM(CASE WHEN gl.personalFouls >= 5 THEN 1 ELSE 0 END),
SUM(gl.points) AS points,
MAX(gl.points),
MIN(gl.points)
)
FROM GameLog gl
WHERE gl.roundId = :roundId AND gl.groupCode = :groupCode AND gl.rosterId IN :rosterIds
GROUP BY
gl.playerId,
gl.seasonStartYear,
gl.lastName,
gl.firstName,
gl.incognito
ORDER BY gamesstarted DESC, games DESC, points DESC, gl.lastName, gl.firstName
].
[140, 141] The constructor expression has two constructor items ('COUNT(DISTINCT gl.gameId)' and 'AS games') that are not separated by a comma.
[204, 205] The constructor expression has two constructor items ('SUM(CASE WHEN gl.hasPlayed = FALSE THEN 1 ELSE 0 END)' and 'AS gamesplayed') that are not separated by a comma.
[271, 272] The constructor expression has two constructor items ('SUM(CASE WHEN gl.starter = TRUE THEN 1 ELSE 0 END)' and 'AS gamesstarted') that are not separated by a comma.
[462, 463] The constructor expression has two constructor items ('SUM(gl.points)' and 'AS points') that are not separated by a comma.
[141, 149] The expression is invalid, which means it does not follow the JPQL grammar.
[205, 219] The expression is invalid, which means it does not follow the JPQL grammar.
[272, 287] The expression is invalid, which means it does not follow the JPQL grammar.
[463, 472] The expression is invalid, which means it does not follow the JPQL grammar.
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:157)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:336)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:280)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:165)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:142)
at org.eclipse.persistence.internal.jpa.JPAQuery.processJPQLQuery(JPAQuery.java:225)
at org.eclipse.persistence.internal.jpa.JPAQuery.prepare(JPAQuery.java:186)
at org.eclipse.persistence.queries.DatabaseQuery.prepareInternal(DatabaseQuery.java:631)
at org.eclipse.persistence.internal.sessions.AbstractSession.processJPAQuery(AbstractSession.java:4502)
at org.eclipse.persistence.internal.sessions.AbstractSession.processJPAQueries(AbstractSession.java:4462)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:645)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:868)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:811)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:256)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:772)
... 201 more
这是关于Hibernate的工作。我认为这将是标准的JPA 2.2,甚至JPA 2.1,在SELECT…
之后放置AS
子句,这样您就可以重用ORDER BY
等子句的标识符
Q:
怎么了?这是EclipseLink的错误/缺少的功能吗?难道它不应该这样工作,因为冬眠有一些额外的肉在这里
如何在构造函数表达式中解决这个问题(而不必重复
ORDER BY
子句中的表达式)?这确实是无效的JPQL,因为select\u item
不是构造函数\u item
。以下是摘自JPA 2.2规范的SELECT子句的语法:
select_clause ::= SELECT [DISTINCT] select_item {, select_item}*
select_item ::= select_expression [ [AS] result_variable]
select_expression ::=
single_valued_path_expression |
scalar_expression |
aggregate_expression |
identification_variable |
OBJECT(identification_variable) |
constructor_expression
constructor_expression ::=
NEW constructor_name ( constructor_item {, constructor_item}* )
constructor_item ::=
single_valued_path_expression |
scalar_expression |
aggregate_expression |
identification_variable
aggregate_expression ::=
{ AVG | MAX | MIN | SUM} ([DISTINCT] state_valued_path_expression) |
COUNT ([DISTINCT] identification_variable | state_valued_path_expression
|single_valued_object_path_expression) |
function_invocation
恐怕在这种情况下没有避免重复的解决方法。在这里的论坛中也有这样的问题: