Problem with query JPQL + JPA + JSF + EJB

1
@Override

public Usuario iniciarSesion(Usuario us){

    Usuario usuario = null;
    String consulta;

    try {
        consulta = "FROM usuario u WHERE u.usuario = ?1 and u.password =?2";
        Query query = em.createQuery(consulta);
        query.setParameter(1, us.getUsuario());
        query.setParameter(2, us.getPassword());
        List<Usuario> lista = query.getResultList();

        if (!lista.isEmpty()) {
            usuario = lista.get(0);

        }

    } catch (Exception e) {
        throw e;

    }
    return usuario;

I get the following error

  

Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.JPQLException   Exception Description: Problem compiling [FROM user u WHERE u.user =? 1 and u.password =? 2].   [5, 12] The abstract schema type 'user' is unknown.   [21, 30] The state field path 'u.user' can not be resolved to a valid type.   [40, 50] The state field path 'u.password' can not be resolved to a valid type.

    
asked by Javier Antonio Aguayo Aguilar 25.10.2016 в 10:53
source

2 answers

3
  

The abstract schema type 'user' is unknown.

In the query From user u ..., the first letter of 'user' is in lowercase, and in your entity it is capitalized 'User'.

    
answered by 25.10.2016 в 11:56
0

The parameters must be a string, try to change them

try {
    consulta = "FROM usuario u WHERE u.usuario = :1 and u.password =:2";
    Query query = em.createQuery(consulta);
    query.setParameter("1", us.getUsuario());
    query.setParameter("2", us.getPassword());
    List<Usuario> lista = query.getResultList();

    if (!lista.isEmpty()) {
        usuario = lista.get(0);

    }

} catch (Exception e) {
    throw e;

}
    
answered by 25.10.2016 в 12:37