2011-04-13 5 views
1

내 애플리케이션의 로그인 방법에 대한 JPQL 쿼리에서 오류를 찾도록 도와 줄 수 있습니까?이 jpql 쿼리에 문제가 있습니까? (JPA)

// 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 이 INVOKE_APPLICATION 5 처리하는 동안 잡은 : UIComponent로부터 된 ClientID = j_idt13 : 에 javax.ejb.EJBException SEVERE : j_idt17, 메시지 =/WEB-INF/템플릿/BasicTemplate.xhtml 61, 63 의 actionListener = "# {securityController.logIn()}"@,691,363 에 javax.ejb.EJBException javax.faces.event.AbortProcessingException : /WEB-INF210 /WEB-INF/templates/BasicTemplate.xhtml 61,63 의 actionListener = "# {securityController.logIn()}"@ /templates/BasicTemplate.xhtml @ 61,63 actionListener = "# {securityController.logIn()}": javax.ejb.EJBException .................. 예외 설명 : 다음 쿼리를 파싱 구문 오류 [역할에서 R을 선택하여 ............ 인한 : java.lang.IllegalArgumentException가하십시오 EntityManager를 쿼리 작성 중에 예외가 발생 r WHERE r.email = : emailparam, r.password = : passwordparam], 줄 1, 열 46 : [,]에 구문 오류가 있습니다. 내부 예외 : MismatchedTokenException (! 79 = - 1) WHERE 절 사이의 연결이없는 쿼리에

+0

@Facepalmed 이봐 친구, Chilax! 나는 4yrs 전에이 질문을 썼다. 그리고 네, 그 때 그것을 시도했습니다. 당신의 것이 건설적인 코멘트는 아니 었습니다. – sfrj

답변

2

. 추가 AND 또는 두 절 사이의 OR : 당신은 아마 추가하는 것을 잊었다

SELECT r FROM Role r WHERE r.email=:emailparam AND r.password=:passwordparam 
5

AND 또는 같은 OR

:

Query query = em 
      .createQuery("SELECT r FROM Role r WHERE r.email=:emailparam AND r.password=:passwordparam"); 
관련 문제