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";
}