你能帮我找出我应用程序登录方法的 JPQL 查询中的错误吗?
// Login
public boolean saveUserState(String email, String password) {
// 1-Send query to database to see if that user exist
Query query = em
.createQuery("SELECT r FROM Role r WHERE r.email=:emailparam r.password=:passwordparam");
query.setParameter("emailparam", email);
query.setParameter("passwordparam", password);
// 2-If the query returns the user(Role) object, store it somewhere in
// the session
Role role = (Role) query.getSingleResult();
if (role != null && role.getEmail().equals(email)
&& role.getPassword().equals(password)) {
FacesContext.getCurrentInstance().getExternalContext()
.getSessionMap().put("userRole", role);
// 3-return true if the user state was saved
return true;
}
// 4-return false otherwise
return false;
}
执行时出现此错误:
SEVERE: JSF1073: javax.faces.event.AbortProcessingException caught during processing of INVOKE_APPLICATION 5 : UIComponent-ClientId=j_idt13:j_idt17, Message=/WEB-INF/templates/BasicTemplate.xhtml @61,63 actionListener="#{securityController.logIn()}": javax.ejb.EJBException SEVERE: /WEB-INF/templates/BasicTemplate.xhtml @61,63 actionListener="#{securityController.logIn()}": javax.ejb.EJBException javax.faces.event.AbortProcessingException: /WEB-INF/templates/BasicTemplate.xhtml @61,63 actionListener="#{securityController.logIn()}": javax.ejb.EJBException .............................. Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: Exception Description: Syntax error parsing the query [SELECT r FROM Role r WHERE r.email=:emailparam, r.password=:passwordparam], line 1, column 46: syntax error at [,]. Internal Exception: MismatchedTokenException(79!=-1)
最佳答案
您可能忘记添加 AND
或 OR
喜欢:
Query query = em
.createQuery("SELECT r FROM Role r WHERE r.email=:emailparam AND r.password=:passwordparam");
关于java - 这个 jpql 查询有什么问题?(JPA),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5647920/