Estou com um erro que não consigo resolver e não sei o motivo Segue erro e minhas classes e view abaixo.
type Exception report
messageInternal Server Error
descriptionThe server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax.el.PropertyNotWritableException: /novo-empregado.xhtml @90,162 value="#{empregadoController.empregado.matricula}": The class 'br.com.loogix.model.Empregado' does not have a writable property 'matricula'.
root cause
javax.faces.component.UpdateModelException: javax.el.PropertyNotWritableException: /novo-empregado.xhtml @90,162 value="#{empregadoController.empregado.matricula}": The class 'br.com.loogix.model.Empregado' does not have a writable property 'matricula'.
root cause
javax.el.PropertyNotWritableException: /novo-empregado.xhtml @90,162 value="#{empregadoController.empregado.matricula}": The class 'br.com.loogix.model.Empregado' does not have a writable property 'matricula'.
root cause
javax.el.PropertyNotWritableException: The class 'br.com.loogix.model.Empregado' does not have a writable property 'matricula'.
classe EmpregadoController.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package br.com.loogix.controller;
import br.com.loogix.dao.AlmoxarifadoDAO;
import br.com.loogix.dao.EmpregadoDAO;
import br.com.loogix.dao.FuncaoDAO;
import br.com.loogix.model.Almoxarifado;
import br.com.loogix.model.Empregado;
import br.com.loogix.model.Funcao;
import javax.inject.Named;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
/**
*
* @author thiago
*/
@Named(value = "empregadoController")
@SessionScoped
public class EmpregadoController implements Serializable {
private static final long serialVersionUID = 1L;
@EJB
private EmpregadoDAO daoEmpregado;
@EJB
private FuncaoDAO daoFuncao;
@EJB
private AlmoxarifadoDAO almoxarifadoDAO;
private Empregado empregado;
private List<Empregado> empregados;
private boolean alterando = false;
private Long idFuncaoEmpregado;
private Long idAlmoxarifadoEmpregado;
public String listar() {
this.empregados = this.daoEmpregado.getList();
return "empregado?faces-redirect=true";
}
public String novo() {
this.idFuncaoEmpregado = null;
this.empregado = new Empregado();
this.alterando = false;
return "novo-empregado?faces-redirect=true";
}
public String iniciarAlterar(Empregado empregado) {
this.empregado = empregado;
this.alterando = true;
return "novo-empregado?faces-redirect=true";
}
public String gravar() {
Funcao funcao = this.daoFuncao.buscaPorId(this.idFuncaoEmpregado);
this.empregado.setFuncao(funcao);
Almoxarifado almoxarifado = this.almoxarifadoDAO.buscaPorId(this.idAlmoxarifadoEmpregado);
this.empregado.setAlmoxarifado(almoxarifado);
if (this.alterando == false)
this.daoEmpregado.add(this.empregado);
else
this.daoEmpregado.update(this.empregado);
this.empregados = this.daoEmpregado.getList();
return "empregado?faces-redirect=true";
}
public String excluir(Empregado empregado) {
this.daoEmpregado.delete(empregado);
this.empregados = this.daoEmpregado.getList();
return null;
}
public Empregado getEmpregado() {
return empregado;
}
public void setEmpregado(Empregado empregado) {
this.empregado = empregado;
}
public List<Empregado> getEmpregados() {
return this.daoEmpregado.getList();
}
public List<Funcao> getFuncoes() {
return this.daoFuncao.getList();
}
public Long getFuncaoEmpregado() {
return idFuncaoEmpregado;
}
public void setFuncaoEmpregado(Long id) {
idFuncaoEmpregado = id;
}
public Long getAlmoxarifadoEmpregado() {
return idAlmoxarifadoEmpregado;
}
public void setAlmoxarifadoEmpregado(Long idAlmoxarifadoEmpregado) {
this.idAlmoxarifadoEmpregado = idAlmoxarifadoEmpregado;
}
public List<Almoxarifado> getAlmoxarifados() {
return this.almoxarifadoDAO.getList();
}
}
Modelo Empregado.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package br.com.loogix.model;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
*
* @author thiago
*/
@Entity
@Table (name = "empregado")
public class Empregado implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "matricula", nullable = false)
private String matricula;
private String nome;
@ManyToOne
@JoinColumn (name = "id_funcao")
private Funcao funcao;
@ManyToOne
@JoinColumn(name = "id_almoxarifado")
private Almoxarifado almoxarifado;
@OneToMany(mappedBy = "empregado")
private List<Saida> saidas;
public Empregado() {
}
public Empregado(Long id, String matricula, String nome, Funcao funcao, Almoxarifado almoxarifado, List<Saida> saidas) {
this.id = id;
this.matricula = matricula;
this.nome = nome;
this.funcao = funcao;
this.almoxarifado = almoxarifado;
this.saidas = saidas;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public Funcao getFuncao() {
return funcao;
}
public void setFuncao(Funcao funcao) {
this.funcao = funcao;
}
public String getMatricula() {
return matricula;
}
public Almoxarifado getAlmoxarifado() {
return almoxarifado;
}
public void setAlmoxarifado(Almoxarifado almoxarifado) {
this.almoxarifado = almoxarifado;
}
public List<Saida> getSaidas() {
return Collections.unmodifiableList(saidas);
}
public void addSaida(Saida saida) {
this.saidas.add(saida);
saida.setEmpregado(this);
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 7;
hash = 83 * hash + Objects.hashCode(this.id);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Empregado other = (Empregado) obj;
if (!Objects.equals(this.id, other.id)) {
return false;
}
return true;
}
}
Meu DAO EmpregadoDAO.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package br.com.loogix.dao;
import br.com.loogix.model.Empregado;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
/**
*
* @author thiago
*/
@Stateless
public class EmpregadoDAO implements Serializable {
private static final long serialVersionUID = 1L;
private GenericDAO<Empregado> dao;
@PersistenceContext
EntityManager em;
@PostConstruct
public void init() {
this.dao = new GenericDAO<Empregado>(this.em);
}
public void add(Empregado empregado) {
this.dao.add(empregado);
}
public void update(Empregado empregado) {
this.dao.update(empregado);
}
public void delete(Empregado empregado) {
empregado = this.em.merge(empregado);
this.dao.delete(empregado);
}
public List<Empregado> getList() {
Query q = em.createQuery("select e from Empregado e");
return q.getResultList();
}
}
Meu formulário em minha view: empregado.xhtml
<h:form>
<div class="clearfix m-t-3">
<h:outputLabel for="matricula" value="Matricula" rendered="false"/>
<h:inputText value="#{empregadoController.empregado.matricula}" id="matricula" pt:placeholder="Digite a matricula do empregado"/>
</div>
<div class="clearfix m-t-1">
<h:outputLabel for="nome" value="Nome:" rendered="false"/>
<h:inputText value="#{empregadoController.empregado.nome}" id="nome" class="form-control" required="true" pt:placeholder="Digite o nome do empregado"/>
</div>
<div class="clearfix m-t-1">
<h:outputLabel for="funcao" value="Função" rendered="false"/>
<h:selectOneMenu id="funcao" value="#{empregadoController.funcaoEmpregado}" class="form-control custom-select">
<f:selectItem itemLabel="Selecionar uma função" itemValue="#{null}" />
<f:selectItems value="#{empregadoController.funcoes}" var="funcao" itemLabel="#{funcao.nome}" itemValue="#{funcao.id}" />
</h:selectOneMenu>
</div>
<div class="clearfix m-t-1">
<h:outputLabel for="almoxarifado" value="Almoxarifado" rendered="false"/>
<h:selectOneMenu id="almoxarifado" value="#{empregadoController.almoxarifadoEmpregado}" class="form-control custom-select">
<f:selectItem itemLabel="Selecionar o número do almoxarifado" itemValue="#{null}" />
<f:selectItems value="#{empregadoController.almoxarifados}" var="almoxarifado" itemLabel="#{almoxarifado.numero}" itemValue="#{almoxarifado.id}" />
</h:selectOneMenu>
</div>
<div class="clearfix m-t-1">
<h:commandButton action="#{empregadoController.gravar()}" value="Gravar empregado" class="btn btn-success form-control" />
</div>