gpt4 book ai didi

java - jpa查询错误:the multi-part identifier could not be bound

转载 作者:行者123 更新时间:2023-11-29 11:26:11 25 4
gpt4 key购买 nike

我在 Spring 应用程序中使用 JPA 自定义查询,其中需要多次查询一张表。

我在存储库中编写此查询:

@Query(value="SELECT *"+
"FROM TBLSTUDENTEQUALITY as e"+
"left join VLE_LOOKUP_DATA as di on e.DISABLE_ID=di.ID"+
"left join VLE_LOOKUP_DATA as d on e.DOMICILE_ID=d.ID"+
"left join VLE_LOOKUP_DATA as n on e.ETHNIC_ID=n.ID"+
"left join VLE_LOOKUP_DATA as g on e.GENDER_ID=g.ID"+
"left join VLE_LOOKUP_DATA as na on e.NATIONALITY_ID=na.ID"+
"left join VLE_LOOKUP_DATA as s on e.SEX_ID=s.ID"+
"left join VLE_LOOKUP_DATA as o on e.SEXORT_ID=o.ID"+
"left join VLE_LOOKUP_DATA as r on e.RELIGION_ID=r.ID"+
"where STUDENT_ID=?1",nativeQuery=true)
public List<StudentEquality> getAll(Long ID);

此查询在 SQL Server 中成功运行,但在 Spring Boot 应用程序中它会产生如下错误:

 java.sql.SQLException: The multi-part identifier "e.DISABLE_ID" could not be bound.

如果我删除 e.disable-id 行,它会出现在下一行。我已经探索了许多资源,大多数建议可能是不存在的列或表名称,但如果这是在这种情况下,它也应该在 SQL Server 中给出错误。

最佳答案

该查询无效,因为每个句子末尾的子句之间没有空格。每行之前或之后添加空格

@Query(value="SELECT * "+
"FROM TBLSTUDENTEQUALITY as e "+
"left join VLE_LOOKUP_DATA as di on e.DISABLE_ID=di.ID "+
"left join VLE_LOOKUP_DATA as d on e.DOMICILE_ID=d.ID "+
"left join VLE_LOOKUP_DATA as n on e.ETHNIC_ID=n.ID "+
"left join VLE_LOOKUP_DATA as g on e.GENDER_ID=g.ID "+
"left join VLE_LOOKUP_DATA as na on e.NATIONALITY_ID=na.ID "+
"left join VLE_LOOKUP_DATA as s on e.SEX_ID=s.ID "+
"left join VLE_LOOKUP_DATA as o on e.SEXORT_ID=o.ID "+
"left join VLE_LOOKUP_DATA as r on e.RELIGION_ID=r.ID "+
"where STUDENT_ID=?1",nativeQuery=true)

关于java - jpa查询错误:the multi-part identifier could not be bound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38160334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com