0
缺少以下內容JPQL query
?帶有IN運算符的枚舉列表,JPQL
SELECT h FROM WorkFlowHistory h WHERE h.referenceNo = :referenceNo
AND h.workflowTask IN ('CONFIRMATION','PAYMENT','ISSUING')
錯誤:
invalid IN expression argument [CONFIRMATION]
動態查詢方法
public List<WorkFlowHistory> findWorkFlowHistoryByRefNo(String refNo, WorkflowTask ...workflowTasks) {
...
StringBuffer buffer = new StringBuffer("SELECT h FROM WorkFlowHistory h WHERE h.referenceNo = :referenceNo");
if(workflowTasks != null && workflowTasks.length > 0) {
buffer.append(" AND h.workflowTask IN (");
for (int i = 0; i < workflowTasks.length; i++) {
buffer.append("'" + workflowTasks[i] + "'");
if ((i + 1) != workflowTasks.length) {
buffer.append(",");
}
}
buffer.append(")");
}
Query q = em.createQuery(buffer.toString());
....
}
我的枚舉類
public enum WorkflowTask {
UNDERWRITING("Underwriting"),
SURVEY("Survey"),
APPROVAL("Approval"),
INFORM("Inform"),
CONFIRMATION("Confirmation"),
PAYMENT("Payment"),
PROPOSAL_REJECT("Proposal Reject"),
ISSUING("Issuing");
private String label;
private WorkflowTask(String label) {
this.label = label;
}
public String getLabel() {
return label;
}
}
Thz,我也在這裏得到它:http://stackoverflow.com/questions/2772305/jpql-in-clause-java-arrays-or-lists-sets謝謝你的支持 – CycDemo