java - 这个 jpql 查询有什么问题?(JPA)

标签 java sql jpa java-ee-6 jpql

你能帮我找出我应用程序登录方法的 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)

最佳答案

您可能忘记添加 ANDOR

喜欢:

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/

相关文章:

java - 如何获取读取文件的进度

mysql - 如何在 where 子句中使用 SOUNDS LIKE

spring - 在spring创建的中间表中插入数据

java - 如何预先加载实体列表?

java - BufferedImage 字节数组操作影响相邻像素

java - 如何在java程序中解决两部电梯的场景

php - 锁定 innoDB 中的行以进行多个查询

C# SqlCommand 命名约定

java - 非抽象对象上的 JPA 延迟加载

java - Jmeter 2.10 HTTP 记录器抛出 keytool 异常