Error between Dao and Bean class

1

I have a problem I am doing a login with jsf and hibernate, I make the query between 3 tables, I ask for the id and the password and it returns the name of the position and in the bean depending on the position it has to go to a different view , but I do the query in the dao and in the bean it sends that as null, when I put the query in mysql it shows me the data and I do a step by step in netbeans and it brings the data, I do not really know what it can be

this is the dao class, the method where the query is

public Instructor finbyUsuario(Instructor instructor) {
        Instructor model = null;
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction transaction = session.beginTransaction();
        String sql = "select cargo.Nombre from instructor INNER JOIN (cargo INNER JOIN asignacion_cargo_instructor ON cargo.CodCargo = asignacion_cargo_instructor.fkCodCargo) ON asignacion_cargo_instructor.fkIdInstructor = instructor.Id where instructor.idInstructor= '"+instructor.getIdInstructor()+"' and instructor.ClaveInstructor='"+instructor.getClaveInstructor()+"'";

        try {
            session.createSQLQuery(sql).addEntity("cargo", Cargo.class).addEntity("instructor", Instructor.class).addEntity("asignacion_cargo_instructor",AsignacionCargoInstructor.class);
            transaction.commit();
            session.close();
        } catch (Exception e) {
            transaction.rollback();
        }
        return model;
    }

and this is the bean

private Instructor instructor;
    private UsuarioDao usuarioDao;

    public loginBean() {
        this.usuarioDao = new UsuarioDaoImp();
        if (this.instructor == null) {
            this.instructor = new Instructor();
        }
    }

    public Instructor getInstructor() {
        return instructor;
    }

    public void setInstructor(Instructor instructor) {
        this.instructor = instructor;
    }


    public String login(ActionEvent event) {
        RequestContext context = RequestContext.getCurrentInstance();
        FacesMessage message;
        boolean loggedIn;


        this.instructor = this.usuarioDao.finbyUsuario(this.instructor);

        try{

            if(this.instructor.equals("Líder del programa")){
                    loggedIn = true;
                    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("instructor", this.instructor.getIdInstructor());
                    return "views/inicio.xhtml";
            }
            if(this.instructor.equals("Instructor Líder de Área")){
                    loggedIn = true;
                    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("instructor", this.instructor.getIdInstructor());
                    return "views/inicio.xhtml";
            }
            if(this.instructor.equals("Instructor etapa lectiva")){
                    loggedIn = true;
                    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("instructor", this.instructor.getIdInstructor());
                    return "views/inicio2.xhtml";
            }
            if(this.instructor.equals("Instructor etapa productiva")){
                    loggedIn = true;
                    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("instructor", this.instructor.getIdInstructor());
                    return "views/inicio.xhtml";
            }
            else {
            loggedIn = false;
            message = new FacesMessage(FacesMessage.SEVERITY_WARN, "Loggin Error", "Usuario y/o Clave es incorrecto");
            this.usuarioDao = new UsuarioDaoImp();
            if (this.instructor == null) {
                this.instructor = new Instructor();
            }

        }

        }catch(Exception e){
            message = new FacesMessage(FacesMessage.SEVERITY_WARN, "Loggin Error", "Usuario y/o Clave es incorrecto");
                }
      return "login.xhtml";
    }
    
asked by Joe Diaz 09.08.2016 в 04:50
source

1 answer

-1

Ensure that the instructor instance that receives the finbyUsuario() method does not have a null value if it does not have a null value, but also ensures that the instructor.getIdInstructor() e instructor.getClaveInstructor() methods obtain a correct value.

String sql = "select cargo.Nombre from instructor INNER JOIN (cargo INNER JOIN asignacion_cargo_instructor ON cargo.CodCargo = asignacion_cargo_instructor.fkCodCargo) ON asignacion_cargo_instructor.fkIdInstructor = instructor.Id where instructor.idInstructor= '"+instructor.getIdInstructor()+"' and instructor.ClaveInstructor='"+instructor.getClaveInstructor()+"'";

There are probably incorrect values, which causes your query to be incorrectly constructed.

Print your StackTrace when the error is generated implementing error handling, so you can see the problem in more detail:

try{
...
... //Código.
...
}catch (Exception e) { 
    e.printStackTrace();
}
    
answered by 09.08.2016 в 14:03