sfr*_*frj 1 java sql jpa jpql java-ee-6
你能帮我找一下我的应用程序中登录方法的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;
}
Run Code Online (Sandbox Code Playgroud)
执行时我收到此错误:
严重:JSF1073:在处理INVOKE_APPLICATION 5期间捕获到javax.faces.event.AbortProcessingException: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 ................ ..............由以下引起:java.lang.IllegalArgumentException:在EntityManager中创建查询时发生异常:异常描述:解析查询时出现语法错误[SELECT r FROM Role r WHERE r. email =:emailparam,r.password =:passwordparam],第1行,第46列:[,]处的语法错误.内部异常:MismatchedTokenException(79!= - 1)
你可能忘了添加AND或OR
喜欢:
Query query = em
.createQuery("SELECT r FROM Role r WHERE r.email=:emailparam AND r.password=:passwordparam");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2321 次 |
| 最近记录: |