我在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服务器中也是如此。
答案 0 :(得分:1)
查询无效,因为每个句子末尾的子句之间没有空格。在每行之前或之后添加空格
@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)