Olá a todos,
Estou começando a usar o JFS + Hibernate e não consigo sair dessa exception, encontrei varias mensagens com o mesmo titulo da minha duvida, mas mesmo assim não conseguir resolver. Então decidir pedir ajudar para alguama alma caridosa aqui do forum.
Desde já agradeço.
Aqui tenho minha classe bean:
package com.mercantilvirtual.entities;
// Generated 07/11/2017 19:46:07 by Hibernate Tools 5.2.5.Final
import java.util.Arrays;
import java.util.Date;
/**
-
UsuariosPdvId generated by hbm2java
*/
public class UsuariosPdvId implements java.io.Serializable {private int codUsuario; private int codGrupos; private String login; private String senha; private String nome; private String email; private String frase; private Character situacao; private String codReferencia; private String ip; private String lat; private String lng; private byte[] imagem; private Character foto; private String abrePreco; private Date ultimoLogin;
public UsuariosPdvId() {
}public UsuariosPdvId(int codUsuario, int codGrupos) { this.codUsuario = codUsuario; this.codGrupos = codGrupos; }
public UsuariosPdvId(int codUsuario, int codGrupos, String login, String senha, String nome, String email, String frase, Character situacao, String codReferencia, String ip, String lat, String lng, byte[] imagem, Character foto, String abrePreco, Date ultimoLogin) { this.codUsuario = codUsuario; this.codGrupos = codGrupos; this.login = login; this.senha = senha; this.nome = nome; this.email = email; this.frase = frase; this.situacao = situacao; this.codReferencia = codReferencia; this.ip = ip; this.lat = lat; this.lng = lng; this.imagem = imagem; this.foto = foto; this.abrePreco = abrePreco; this.ultimoLogin = ultimoLogin; }
public int getCodUsuario() { return this.codUsuario; }
public void setCodUsuario(int codUsuario) { this.codUsuario = codUsuario; }
public int getCodGrupos() { return this.codGrupos; }
public void setCodGrupos(int codGrupos) { this.codGrupos = codGrupos; }
public String getLogin() { return this.login; }
public void setLogin(String login) { this.login = login; }
public String getSenha() { return this.senha; }
public void setSenha(String senha) { this.senha = senha; }
public String getNome() { return this.nome; }
public void setNome(String nome) { this.nome = nome; }
public String getEmail() { return this.email; }
public void setEmail(String email) { this.email = email; }
public String getFrase() { return this.frase; }
public void setFrase(String frase) { this.frase = frase; }
public Character getSituacao() { return this.situacao; }
public void setSituacao(Character situacao) { this.situacao = situacao; }
public String getCodReferencia() { return this.codReferencia; }
public void setCodReferencia(String codReferencia) { this.codReferencia = codReferencia; }
public String getIp() { return this.ip; }
public void setIp(String ip) { this.ip = ip; }
public String getLat() { return this.lat; }
public void setLat(String lat) { this.lat = lat; }
public String getLng() { return this.lng; }
public void setLng(String lng) { this.lng = lng; }
public byte[] getImagem() { return this.imagem; }
public void setImagem(byte[] imagem) { this.imagem = imagem; }
public Character getFoto() { return this.foto; }
public void setFoto(Character foto) { this.foto = foto; }
public String getAbrePreco() { return this.abrePreco; }
public void setAbrePreco(String abrePreco) { this.abrePreco = abrePreco; }
public Date getUltimoLogin() { return this.ultimoLogin; }
public void setUltimoLogin(Date ultimoLogin) { this.ultimoLogin = ultimoLogin; }
public boolean equals(Object other) { if ((this == other)) return true; if ((other == null)) return false; if (!(other instanceof UsuariosPdvId)) return false; UsuariosPdvId castOther = (UsuariosPdvId) other;
return (this.getCodUsuario() == castOther.getCodUsuario()) && (this.getCodGrupos() == castOther.getCodGrupos()) && ((this.getLogin() == castOther.getLogin()) || (this.getLogin() != null && castOther.getLogin() != null && this.getLogin().equals(castOther.getLogin()))) && ((this.getSenha() == castOther.getSenha()) || (this.getSenha() != null && castOther.getSenha() != null && this.getSenha().equals(castOther.getSenha()))) && ((this.getNome() == castOther.getNome()) || (this.getNome() != null && castOther.getNome() != null && this.getNome().equals(castOther.getNome()))) && ((this.getEmail() == castOther.getEmail()) || (this.getEmail() != null && castOther.getEmail() != null && this.getEmail().equals(castOther.getEmail()))) && ((this.getFrase() == castOther.getFrase()) || (this.getFrase() != null && castOther.getFrase() != null && this.getFrase().equals(castOther.getFrase()))) && ((this.getSituacao() == castOther.getSituacao()) || (this.getSituacao() != null && castOther.getSituacao() != null && this.getSituacao().equals(castOther.getSituacao()))) && ((this.getCodReferencia() == castOther.getCodReferencia()) || (this.getCodReferencia() != null && castOther.getCodReferencia() != null && this.getCodReferencia().equals(castOther.getCodReferencia()))) && ((this.getIp() == castOther.getIp()) || (this.getIp() != null && castOther.getIp() != null && this.getIp().equals(castOther.getIp()))) && ((this.getLat() == castOther.getLat()) || (this.getLat() != null && castOther.getLat() != null && this.getLat().equals(castOther.getLat()))) && ((this.getLng() == castOther.getLng()) || (this.getLng() != null && castOther.getLng() != null && this.getLng().equals(castOther.getLng()))) && ((this.getImagem() == castOther.getImagem()) || (this.getImagem() != null && castOther.getImagem() != null && Arrays.equals(this.getImagem(), castOther.getImagem()))) && ((this.getFoto() == castOther.getFoto()) || (this.getFoto() != null && castOther.getFoto() != null && this.getFoto().equals(castOther.getFoto()))) && ((this.getAbrePreco() == castOther.getAbrePreco()) || (this.getAbrePreco() != null && castOther.getAbrePreco() != null && this.getAbrePreco().equals(castOther.getAbrePreco()))) && ((this.getUltimoLogin() == castOther.getUltimoLogin()) || (this.getUltimoLogin() != null && castOther.getUltimoLogin() != null && this.getUltimoLogin().equals(castOther.getUltimoLogin())));
}
public int hashCode() {
int result = 17;result = 37 * result + this.getCodUsuario(); result = 37 * result + this.getCodGrupos(); result = 37 * result + (getLogin() == null ? 0 : this.getLogin().hashCode()); result = 37 * result + (getSenha() == null ? 0 : this.getSenha().hashCode()); result = 37 * result + (getNome() == null ? 0 : this.getNome().hashCode()); result = 37 * result + (getEmail() == null ? 0 : this.getEmail().hashCode()); result = 37 * result + (getFrase() == null ? 0 : this.getFrase().hashCode()); result = 37 * result + (getSituacao() == null ? 0 : this.getSituacao().hashCode()); result = 37 * result + (getCodReferencia() == null ? 0 : this.getCodReferencia().hashCode()); result = 37 * result + (getIp() == null ? 0 : this.getIp().hashCode()); result = 37 * result + (getLat() == null ? 0 : this.getLat().hashCode()); result = 37 * result + (getLng() == null ? 0 : this.getLng().hashCode()); int imagemHashcode = 0; byte[] imagemProperty = this.getImagem(); if (imagemProperty != null) { imagemHashcode = 1; for (int i = 0; i < imagemProperty.length; i++) { imagemHashcode = 37 * imagemHashcode + imagemProperty[i]; } } result = 37 * result + imagemHashcode; result = 37 * result + (getFoto() == null ? 0 : this.getFoto().hashCode()); result = 37 * result + (getAbrePreco() == null ? 0 : this.getAbrePreco().hashCode()); result = 37 * result + (getUltimoLogin() == null ? 0 : this.getUltimoLogin().hashCode()); return result;
}
}
Aqui minha Classe DAO
package com.mercantilvirtual.dao;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.persistence.Query;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.mercantilvirtual.entities.UsuariosPdvId;
import com.mercantilvirtual.util.HibernateUtil;
import java.util.ArrayList;
public class LoginDB {
private Session session;
public UsuariosPdvId verificaDados(UsuariosPdvId usuario){
UsuariosPdvId us = null;
try{
session = HibernateUtil.getSessionFactory().openSession();
String hql = "From usuarios_pdv where login = '" + usuario.getLogin() + "' and senha = '" + usuario.getSenha() + "'";
Query query = session.createQuery(hql);
if(!query.getResultList().isEmpty()){
us = (UsuariosPdvId) query.getResultList().get(0);
}
}catch(Exception e){
throw e;
}
return us;
}
}
Aqui minha Classe de usuario:
package com.mercantilvirtual.controller;
import javax.faces.bean.*;
import javax.faces.context.FacesContext;
import javax.persistence.Entity;
import com.mercantilvirtual.dao.LoginDB;
import com.mercantilvirtual.entities.UsuariosPdvId;
@ManagedBean(name = “login_bean”)
@SessionScoped
@Entity
public class Usuario implements java.io.Serializable {
private UsuariosPdvId usuario;
private String mensagem;
public String getMensagem() {
return mensagem;
}
public void setMensagem(String mensagem) {
this.mensagem = mensagem;
}
public UsuariosPdvId getUsuario() {
return usuario;
}
public void setUsuario(UsuariosPdvId usuario) {
this.usuario = usuario;
}
public Usuario() {
}
public String verificaDados() throws Exception{
LoginDB lg = new LoginDB();
UsuariosPdvId us;
String resultado = null;
try {
us = lg.verificaDados(this.usuario);
System.out.println("aqui 01");
if(us != null){
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("usuario", us);
resultado = "ok";
}else {
resultado = "error";
}
}catch(Exception e) {
throw e;
}
return resultado;
}
}
E aqui meu XHTML:
<h:head></h:head>
<h:outputLabel value="Senha:" />
<h:inputSecret value="#{login_bean.usuario.senha}" size="20" />
<h:commandButton value="Logar" action="#{usuario.verificaDados()}" />
<h:outputText id="loginText" value="#{login_bean.mensagem}"/>
</h:panelGrid>
<h:messages />
</h:form>
E quando clico no botão Logar aparece esse erro:
22:10:07,055 ERROR [io.undertow.request] (default task-3) UT005023: Exception handling request to /mercantilvirtual/faces/index.xhtml;jsessionid=DR3elZm4W-fOiHex9A4ilSQby_MVnOwxLmZDUZGe.casa-pc: javax.servlet.ServletException: /index.xhtml @12,74 value="#{login_bean.usuario.login}": Target Unreachable, ‘null’ returned null
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.el.PropertyNotFoundException: /index.xhtml @12,74 value="#{login_bean.usuario.login}": Target Unreachable, ‘null’ returned null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1045)
at javax.faces.component.UIInput.validate(UIInput.java:975)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1248)
at javax.faces.component.UIInput.processValidators(UIInput.java:712)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
… 37 more
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, ‘null’ returned null
at com.sun.el.parser.AstValue.getTarget(AstValue.java:191)
at com.sun.el.parser.AstValue.getType(AstValue.java:85)
at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201)
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)