[英]What is wrong with this jpql query?(JPA)
Can you help me find the error in my JPQL query of the login method in my application please? 您能帮我在我的应用程序中的登录方法的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;
}
I am getting this error when it executes: 执行时出现此错误:
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 [,]. 严重:JSF1073:在处理INVOKE_APPLICATION 5期间捕获到javax.faces.event.AbortProcessingException:UIComponent-ClientId = j_idt13:j_idt17,消息= / WEB-INF / templates / BasicTemplate.xhtml @ 61,63 actionListener =“#{securityController.logIn ()}“:javax.ejb.EJBException严重:/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列:[,]处的语法错误。 Internal Exception: MismatchedTokenException(79!=-1) 内部异常:MismatchedTokenException(79!=-1)
You probably forgot to add AND
or OR
您可能忘了添加AND
或OR
like: 喜欢:
Query query = em
.createQuery("SELECT r FROM Role r WHERE r.email=:emailparam AND r.password=:passwordparam");
In your query the link between the WHERE clauses is missing. 在您的查询中,WHERE子句之间的链接丢失。 Add an AND
or an OR
between both clauses: 在两个子句之间添加AND
或OR
:
SELECT r FROM Role r WHERE r.email=:emailparam AND r.password=:passwordparam
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.