2016-07-27 56 views
-1

我有以下Spring Data查詢:SQL:無論列名是否存在?

@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 

但是,我知道,在我的查詢中的兩個表我所有的列名是正確的,有什麼事情ne造成這種情況?

+0

不應該有「的周圍的查詢 – Stultuske

+0

能?你張貼表格嗎? – Danieboy

+0

你可以張貼表格和t嗎?他的實體bean? – isnot2bad

回答

0

我不知道你的數據的結構,但你的春天數據查詢有許多錯別字和錯誤,標準查詢方法應該是:

@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列或family_id可能這就是爲什麼你收到這樣的錯誤的別名的列..

+1

右側括號缺失,我想。 – RealSkeptic