SQL:列名无效,那么列是什么?

时间:2016-07-27 12:45:38

标签: java sql oracle jdbc spring-data

我有以下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

但是,我知道我的查询中两个表的所有列名都是正确的,这可能导致什么?

1 个答案:

答案 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_idrelated_person_id之间的关系 - 但它应该返回family_id列或别名列{{ 1}}可能就是为什么你会收到这样的错误..