"; 预期 "., ("; 运行 JPA 查询
"; expected "., ("; running JPA query
我有这个 jpa 查询
@Query(nativeQuery = true, value = "with\n"
+ " 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_fin\n"
+ " from AUTORISATION_BONANSA_ASSIGNATION aga\n"
+ " inner join site s on aga.site_id = s.site_id\n"
+ " where ?1 between aga.dt_debut and aga.dt_fin\n"
+ " )\n"
+ "select ag.AUTORISATION_BONANSAS_ID, ag.NOM, ag.PRENOM, ag.EULOGIN, ag.dt_Debut, ag.dt_Fin\n"
+ " , aga.iBonansaAffectation_id, aga.iSiteNoTypeBaseData_id, aga.iSiteNoTypeBaseData_nom\n"
+ " , aga.iBonansaAffectation_dt_debut, aga.iBonansaAffectation_dt_fin\n"
+ "from autorisation_bonansa ag\n"
+ "left join validBonansasAssignation aga on ag.autorisation_bonansas_id = aga.autorisation_bonansas_id\n"
+ "where ?1 between ag.dt_debut and ag.dt_fin\n"
+ "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 = ?
我试了一下,看看行不行。
我有这个 jpa 查询
@Query(nativeQuery = true, value = "with\n"
+ " 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_fin\n"
+ " from AUTORISATION_BONANSA_ASSIGNATION aga\n"
+ " inner join site s on aga.site_id = s.site_id\n"
+ " where ?1 between aga.dt_debut and aga.dt_fin\n"
+ " )\n"
+ "select ag.AUTORISATION_BONANSAS_ID, ag.NOM, ag.PRENOM, ag.EULOGIN, ag.dt_Debut, ag.dt_Fin\n"
+ " , aga.iBonansaAffectation_id, aga.iSiteNoTypeBaseData_id, aga.iSiteNoTypeBaseData_nom\n"
+ " , aga.iBonansaAffectation_dt_debut, aga.iBonansaAffectation_dt_fin\n"
+ "from autorisation_bonansa ag\n"
+ "left join validBonansasAssignation aga on ag.autorisation_bonansas_id = aga.autorisation_bonansas_id\n"
+ "where ?1 between ag.dt_debut and ag.dt_fin\n"
+ "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 = ?
我试了一下,看看行不行。