我有以下Spring Data
查询:
@Query(value = "select * from person where person_id =?! and family_id not in (select related_person_id from relationships where related_family_id = ?1)", native query = true)
Person getPerson(String personId);
我收到错误:
Caused by: java.sql.SQLException: Invalid column name
但是,我知道我的查询中两个表的所有列名都是正确的,这可能导致什么?
答案 0 :(得分:0)
我不知道您的数据结构,但您的spring数据查询有很多拼写错误,标准查询方法应该是:
@Query(value = "select * from person where person_id =?1 and family_id not in (select related_person_id from relationships where related_family_id = ?2)", nativeQuery = true);
Person findByPersonIdAndRelatedFamilyId(String personId, String relatedFamilyId);
还要检查您的内部选择查询 - 我不知道family_id
和related_person_id
之间的关系 - 但它应该返回family_id
列或别名列{{ 1}}可能就是为什么你会收到这样的错误..