antlr.NoViableAltException:意外令牌,WHERE子句和意外令牌

时间:2018-05-10 07:01:17

标签: java sql spring hibernate exception

我已经搜索了与此相关的其他问题,但我刚刚意识到可能是在我的查询中可能是这个问题发生了或者在hibernate中

SEE where子句,它尚未被调用 可能是什么问题?

这是整个代码         尝试{             //逐个检查选择字段             String query =“选择emp.employeeID,emp.firstName,emp.middleName,emp.lastName,pos.positionName,dept.deptName,work.workplaceName”                     +“来自Employee emp”                     +“INNER JOIN Department dept”                         +“ON emp.departmentID = dept.deptID”                     +“INNER JOIN Position pos”                         +“ON emp.positionID = pos.positionID”                     +“INNER JOIN Workplace work”                         +“ON emp.workplaceID = work.workplaceID”;

                if(checkAllNotEmpty(data)) {
                    query = query.concat("WHERE ");

                    if(data.getEmployeeID() != null && !data.getEmployeeID().equals("")) {  
                        criteria.add(CRITERIA_EMPLOYEEID2);
                        System.out.println("Employee IDs");
                        input_empID = true;
                    } 

                    if(data.getEmployeeName()!= null && !data.getEmployeeName().equals("")){ 
                        criteria.add(nameCriteriaHelper(data.getEmployeeName()));
                        System.out.println("Employee Name AKOOO");
                        input_empName = true;
                    }

                    if(data.getDepartmentID()!=0) {
                        criteria.add(CRITERIA_DEPARTMENT);
                        System.out.println("Dept ID ");
                        selected_dept = true;
                    }
                    if(data.getPositionID()!=0) {
                        criteria.add(CRITERIA_POSITION);
                        System.out.println("POS ID ");
                        selected_pos = true;
                    }
                    if(data.getWorkplaceID()!=0) {
                        criteria.add(CRITERIA_WORKPLACE);
                        selected_work = true;
                    }

                    query = query.concat(String.join(" OR ", criteria));
                }
                query = query.concat(" ORDER BY emp.joinDate DESC");
                System.out.println("QUERY: " + query);
                Query q = session.createQuery(query);
                if(input_empID) {
                    q.setParameter("id", "%" + data.getEmployeeID() + "%");
                }
                if(input_empName) {
                    if(searchbyOne)
                        q.setParameter("inputName", "%" + data.getEmployeeName() + "%");
                    if(searchbyFandL)
                        q.setParameter("firstLastName", "%" +firstLastName+ "%");
                    if(searchbyCompName)
                        q.setParameter("completeName", "%" +completeName+ "%");
                }

                if(selected_dept) {
                    q.setParameter("deptID", data.getDepartmentID());
                }
                if(selected_pos) {
                    q.setParameter("posID", data.getPositionID());
                }
                if(selected_work) {
                    q.setParameter("workID", data.getWorkplaceID());
                }
                employees = (List<Object>) q.list();
    }catch(Exception e){
        e.printStackTrace();
    }finally{
        session.close();
    }

    return employees;
}

所以帮助T.T

0 个答案:

没有答案