";预期".,(";运行 JPA 查询



我有这个jpa查询

@Query(nativeQuery = true, value = "withn"
+ "    validBonansasAssignation as (n"
+ "        select aga.autorisation_bonansas_id, aga.autorisation_bonansa_assign_id as iBonansaAffectation_id,n"
+ "               s.site_id as ISiteNoTypeBaseData_id, s.desc_court as iSiteNoTypeBaseData_nom,n"
+ "               aga.dt_debut as iBonansaAffectation_dt_debut, aga.dt_fin as iBonansaAffectation_dt_finn"
+ "        from AUTORISATION_BONANSA_ASSIGNATION agan"
+ "        inner join site s on aga.site_id = s.site_idn"
+ "        where ?1 between aga.dt_debut and aga.dt_finn"
+ "    )n"
+ "select ag.AUTORISATION_BONANSAS_ID, ag.NOM, ag.PRENOM, ag.EULOGIN, ag.dt_Debut, ag.dt_Finn"
+ "    , aga.iBonansaAffectation_id, aga.iSiteNoTypeBaseData_id, aga.iSiteNoTypeBaseData_nomn"
+ "    , aga.iBonansaAffectation_dt_debut, aga.iBonansaAffectation_dt_finn"
+ "from autorisation_bonansa agn"
+ "left join validBonansasAssignation aga on ag.autorisation_bonansas_id = aga.autorisation_bonansas_idn"
+ "where ?1 between ag.dt_debut and ag.dt_finn"
+ "and ag.organisation_id = ?2")
List<AutoUsers> find(Date date, Long id);

但当我运行测试时,我会出现以下错误:

org.springframework.orm.jpa.JpaSystemException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.2.v20180622-f627448): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "WITH
VALIDBONANSASASSIGNATION AS[*] (
SELECT AGA.AUTORISATION_BONANSAS_ID, AGA.AUTORISATION_BONANSA_ASSIGN_ID AS IBONANSAAFFECTATION_ID,
S.SITE_ID AS ISITENOTYPEBASEDATA_ID, S.DESC_COURT AS ISITENOTYPEBASEDATA_NOM,
AGA.DT_DEBUT AS IBONANSAAFFECTATION_DT_DEBUT, AGA.DT_FIN AS IBONANSAAFFECTATION_DT_FIN
FROM AUTORISATION_BONANSA_ASSIGNATION AGA
INNER JOIN SITE S ON AGA.SITE_ID = S.SITE_ID
WHERE ? BETWEEN AGA.DT_DEBUT AND AGA.DT_FIN
)
SELECT AG.AUTORISATION_BONANSAS_ID, AG.NOM, AG.PRENOM, AG.EULOGIN, AG.DT_DEBUT, AG.DT_FIN
, AGA.IBONANSAAFFECTATION_ID, AGA.ISITENOTYPEBASEDATA_ID, AGA.ISITENOTYPEBASEDATA_NOM
, AGA.IBONANSAAFFECTATION_DT_DEBUT, AGA.IBONANSAAFFECTATION_DT_FIN
FROM AUTORISATION_BONANSA AG
LEFT JOIN VALIDBONANSASASSIGNATION AGA ON AG.AUTORISATION_BONANSAS_ID = AGA.AUTORISATION_BONANSAS_ID
WHERE ? BETWEEN AG.DT_DEBUT AND AG.DT_FIN
AND AG.ORGANISATION_ID = ? "; expected "., ("; SQL statement:

你能像下面这样设置nativeQuery = true吗?看看这是否有效。

@Query(
value = "SELECT * FROM USERS u WHERE u.status = 1", 
nativeQuery = true)

JPA从错误堆栈生成原始查询的方式,我建议如下所示进行更改,然后尝试

我现在没有IDE来实际修改正确格式的查询,所以以SQL格式提供了查询,但目的是将列定义到WITH子句中,因为正如您在错误堆栈中看到的,它是像WITH VALIDBONANSASASSIGNATION AS[*] (一样生成的,而AS之后的[*]是Oracle无法识别并引发语法错误的。

WITH VALIDBONANSASASSIGNATION 
(
AUTORISATION_BONANSAS_ID
, IBONANSAAFFECTATION_ID
, ISITENOTYPEBASEDATA_ID
, ISITENOTYPEBASEDATA_NOM
, IBONANSAAFFECTATION_DT_DEBUT
, IBONANSAAFFECTATION_DT_FIN
)
AS
(
SELECT AGA.AUTORISATION_BONANSAS_ID
, AGA.AUTORISATION_BONANSA_ASSIGN_ID AS IBONANSAAFFECTATION_ID
, S.SITE_ID AS ISITENOTYPEBASEDATA_ID
, S.DESC_COURT AS ISITENOTYPEBASEDATA_NOM
, AGA.DT_DEBUT AS IBONANSAAFFECTATION_DT_DEBUT
, AGA.DT_FIN AS IBONANSAAFFECTATION_DT_FIN
FROM AUTORISATION_BONANSA_ASSIGNATION AGA
INNER JOIN SITE S 
ON AGA.SITE_ID = S.SITE_ID
WHERE ? BETWEEN AGA.DT_DEBUT 
AND AGA.DT_FIN
)
SELECT AG.AUTORISATION_BONANSAS_ID
, AG.NOM
, AG.PRENOM
, AG.EULOGIN
, AG.DT_DEBUT
, AG.DT_FIN
, AGA.IBONANSAAFFECTATION_ID
, AGA.ISITENOTYPEBASEDATA_ID
, AGA.ISITENOTYPEBASEDATA_NOM
, AGA.IBONANSAAFFECTATION_DT_DEBUT
, AGA.IBONANSAAFFECTATION_DT_FIN
FROM AUTORISATION_BONANSA AG
LEFT JOIN VALIDBONANSASASSIGNATION AGA 
ON AG.AUTORISATION_BONANSAS_ID 
= AGA.AUTORISATION_BONANSAS_ID
WHERE ? BETWEEN AG.DT_DEBUT AND AG.DT_FIN
AND AG.ORGANISATION_ID = ?

我试了一下,看看它是否有效。

相关内容

  • 没有找到相关文章

最新更新