[英]What is wrong with this jpql query?(JPA)
您能幫我在我的應用程序中的登錄方法的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;
}
執行時出現此錯誤:
嚴重: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列:[,]處的語法錯誤。 內部異常:MismatchedTokenException(79!=-1)
您可能忘了添加AND
或OR
喜歡:
Query query = em
.createQuery("SELECT r FROM Role r WHERE r.email=:emailparam AND r.password=:passwordparam");
在您的查詢中,WHERE子句之間的鏈接丟失。 在兩個子句之間添加AND
或OR
:
SELECT r FROM Role r WHERE r.email=:emailparam AND r.password=:passwordparam
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.