You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JPA2与EclipseLink 2.7.3中EXTRACT函数报错问题求助

Alright, let's get to the bottom of this confusing error you're facing. The root cause is a simple JPQL syntax mistake in how you're using the EXTRACT function—EclipseLink's query parser isn't recognizing it as a function call, which is why it's treating EXTRACT like an undefined identification variable.

What Went Wrong

You wrote the EXTRACT function with a comma separator:

EXTRACT(DAY,s.lastExecutionDate)

But the correct JPQL syntax for EXTRACT (supported by JPA 2.1 and EclipseLink 2.7.x) requires using the FROM keyword to separate the date component and the date expression. When you use a comma, the parser misinterprets EXTRACT as a variable that should be declared in the FROM clause—hence the error message you're seeing.

Corrected Named Query

Here's the fixed version of your query, with the proper EXTRACT syntax:

@NamedQuery(
    name = User.FIND_USER_CWC_ERROR_TODAY,
    query = "select u from User u, Score s " +
            "where u.id = s.userId " +
            "and s.status = com.model.Status.ERROR " +
            "and s.scoreType = com.model.ScoreType.CREDIT " +
            "and EXTRACT(DAY FROM s.lastExecutionDate) = EXTRACT(DAY FROM CURRENT_DATE)"
)

Quick Note on EXTRACT Usage

EclipseLink 2.7.3 fully supports the JPA 2.1 EXTRACT function, which follows this standard format:

EXTRACT(<date_component> FROM <date_expression>)

Valid date components include DAY, MONTH, YEAR, HOUR, MINUTE, SECOND, etc. Using this syntax ensures the parser correctly identifies it as a function rather than an undefined variable.

内容的提问来源于stack exchange,提问作者cyril

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:07:59