我試圖做到這一點選擇:JPA,春Webservice的選擇與NOT IN和IN
SELECT c FROM Incident c
WHERE c.incidentID IN
(
SELECT DISTINCT d.incidentID FROM TagIncident d WHERE tagName IN (d.tagName=?1)
AND d.incidentID NOT IN
(SELECT a.incidentID FROM TagIncident a WHERE tagName IN (a.tagName=?2))
)
在我與JPA /彈簧系統,我發現了錯誤:
"HTTP Status 500 - Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: An exception occurred while creating a query in EntityManager:"
是我在語法上做錯了嗎? 我在我的數據庫(HANA)上測試過它,它工作正常。
感謝您的幫助!
編輯更多的錯誤日誌
我最新的嘗試是:
SELECT c FROM Incident c WHERE c.incidentID IN
(SELECT DISTINCT d.incidentID FROM TagIncident d WHERE d.tagName IN
(d.tagName=?1) AND d.incidentID NOT IN
(SELECT a.incidentID FROM TagIncident a WHERE a.tagName IN (a.tagName=?2)))
編輯
Exception Description: Syntax error parsing [SELECT c FROM Incident c WHERE c.incidentID IN (SELECT DISTINCT d.incidentID FROM TagIncident d WHERE d.tagName IN (d.tagName=?1) AND d.incidentID NOT IN (SELECT a.incidentID FROM TagIncident a WHERE a.tagName IN (a.tagName=?2)))]. [117, 131]
The expression at index {0} is not a valid expression. [215, 229]
The expression at index {0} is not a valid expression.; nested exception is java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: Exception Description: Syntax error parsing [SELECT c FROM Incident c WHERE c.incidentID IN (SELECT DISTINCT d.incidentID FROM TagIncident d WHERE d.tagName IN (d.tagName=?1) AND d.incidentID NOT IN (SELECT a.incidentID FROM TagIncident a WHERE a.tagName IN (a.tagName=?2)))]. [117, 131]
The expression at index {0} is not a valid expression. [215, 229]
The expression at index {0} is not a valid expression.] with root cause Local Exception Stack: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.JPQLException Exception Description: Syntax error parsing [SELECT c FROM Incident c WHERE c.incidentID IN (SELECT DISTINCT d.incidentID FROM TagIncident d WHERE d.tagName IN (d.tagName=?1) AND d.incidentID NOT IN (SELECT a.incidentID FROM TagIncident a WHERE a.tagName IN (a.tagName=?2)))]. [117, 131]
The expression at index {0} is not a valid expression. [215, 229]
The expression at index {0} is not a valid expression.
最新嘗試:
List<String> list_add_tags = new ArrayList<String>();
List<String> list_remove_tags = new ArrayList<String>();
// creating custom sql_query
String sql_query = "SELECT c FROM Incident c WHERE c.incidentID IN (SELECT DISTINCT(d.incidentID) FROM TagIncident d WHERE d.tagName IN (:add_tags) AND d.incidentID NOT IN (SELECT a.incidentID FROM TagIncident a WHERE a.tagName IN (:remove_tags)))";
TypedQuery<Incident> query = em.createQuery(sql_query, Incident.class);
query.setParameter("add_tags", list_add_tags);
query.setParameter("remove_tags", list_remove_tags);
return query.getResultList();
仍然不起作用。 =(
錯誤:
You have attempted to set a value of type class java.util.ArrayList for parameter add_tags with expected type of class java.lang.String
哪些JPA提供商您使用的? Hibernate,EclipseLink,OpenJPA還是其中一個鮮爲人知的DataNucleaus,Toplink,ObjectDB?在Hibernate中,您可以指定列表,如章節4.6.17.5 JPA規範中的示例所示,但用他們自己的話來說,他們認爲他們支持它作爲獎勵功能。也許你應該嘗試去除參數周圍的括號?官方的例子確實意味着你不應該需要它們。 – coladict
EclipseLink 2.6.0,從列表中刪除了IN的括號,它的工作原理,通過這樣做我能理解什麼?我如何檢查我的JPA版本? –