Olá pessoal da comunidade. Venho a vcs novamente solicitar ajuda. Estou tentando passar um telefone para um usuário que tem relacionamento manytoOne.
Porem quando tento fazer o cadastro do tel aparece um erro: Message /cadastroDeTelefone.xhtml @35,67 value="#{telefoneBean.usuario.id}": Target Unreachable, [usuario] returned null
Exception
javax.servlet.ServletException: /cadastroDeTelefone.xhtml @35,67 value="#{telefoneBean.usuario.id}": Target Unreachable, [usuario] returned null javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Eu acho que é porque você está mapeando pelo usuário, e está retornando null. Mapeia pelo id. E cria o equals e o hash code pro Id e cria uma estratégia pro id @GeneratedValue(strategy = GenerationType.IDENTITY).
E não seria melhor também colocar alguns @size e substituir esse “(nullable = false)” por @NotBlank ou @NotNull ?
V
valterchess
O equals e o hash code podem ser gerados automaticamente, tipo getters e setters. No sources, vc vai ver um pouco abaixo do generate getters() and setters. + ou - Assim: generate hashCode() and equals()…