【问题标题】:java.lang.IllegalArgumentException: The FROM clause of the query does not declare an identification variable [foo]java.lang.IllegalArgumentException:查询的 FROM 子句未声明标识变量 [foo]
【发布时间】:2014-05-18 21:44:47
【问题描述】:
Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Error compiling the query [select t from Utilisateur t where LOGIN='' and PASSWORD=''], line 1, column 34: unknown identification variable [login]. The FROM clause of the query does not declare an identification variable [login].
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1477)
    at ejbservice.GestionUtulisateur.authentification(GestionUtulisateur.java:79)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

我的错误是什么,请帮助我,这是我的方法

public boolean authentification(String login, String password) {
     String a = "select t from Utilisateur t where LOGIN='"+login+"' and PASSWORD='"+password+"'";
     EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProjetPU");
     EntityManager em = emf.createEntityManager();
     Query query = em.createQuery(a);
     List <Utilisateur> Loaded = query.getResultList();
     if ((Loaded.size())==0 ){
         return false ;
     } else {
         return true;
     }
}

【问题讨论】:

  • LOGINPASSWORD property 是 Utilisateur 的名称吗?如果是,您应该使用t.LOGINt.PASSWORD

标签: jpa jpql


【解决方案1】:

语法不正确。假设您的 Utilisateur.java 实际上确实具有名为 LOGINPASSWORD 的属性,您将使用如下 JPQL 表达式:

select t from Utilisateur t where t.LOGIN='...' and t.PASSWORD='...'

我猜。但这些对我来说似乎是表列名(因为将属性声明为小写的约定)。检查您是否没有将列与属性混淆。

【讨论】:

    【解决方案2】:

    您正在使用 JPQL 查询,因此您应该使用 setParameter 来传递参数: 试试这个:

    String a = "select t from Utilisateur t where LOGIN= :loginParam and PASSWORD= :passwordParam";
    Query query = em.createQuery(a);
    ...
    query.setParameter("loginParam",login);
    query.setParameter("passwordParam",password);
    List <Utilisateur> Loaded = query.getResultList();
    ...
    

    【讨论】:

      猜你喜欢
      • 2021-08-17
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      • 2015-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多