Boas colegas, estou com um problema a uns dias que não consigo resolver pretendo persistir um objecto cujo os seus atributos são objectos de outras classe. Estou a usar o thymealeaf para ajudar me a preparar o formulário. Para melhor deixar claro irei deixar os códigos abaixo:
Primeiramente tentei usar código abaixo na view de cadastro mas deu o seguinte erro: Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'utenteEmprestimo' of bean class [mz.com.centropontoencontro.domain.Emprestimo]: Bean property 'utenteEmprestimo' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
O código:
classe de dominio do objecto que pretendo persistir:
@Entity
@Table(name = “emp_emprestimo”)
public class Emprestimo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = “emp_id”)
private Long id;
@ManyToOne
@JoinColumn(name = "emp_utenteId")
private Utente utenteEmprestimo;
@ManyToOne
@JoinColumn(name = "emp_livroId")
private Livro livroEmprestimo;
@Column(name = "emp_dataRegisto")
private LocalDateTime dataRegisto;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Utente getUtente() {
return utenteEmprestimo;
}
public void setUtente(Utente utente) {
this.utenteEmprestimo = utente;
}
public Livro getLivro() {
return livroEmprestimo;
}
public void setLivro(Livro livro) {
this.livroEmprestimo = livro;
}
public LocalDateTime getDataRegisto() {
return dataRegisto;
}
public void setDataRegisto(LocalDateTime dataRegisto) {
this.dataRegisto = dataRegisto;
}
}
Classes de domínio de outros objectos
@Entity
@Table (name = “ute_utente”)
public class Utente{
@Column(name = "ute_id")
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "ute_nome", length = 100, nullable = false)
private String nome;
@Column(name = "ute_dataNascimento")
@DateTimeFormat(iso = ISO.DATE)
private LocalDate dataNascimento;
@Column(name = "ute_genero", nullable = false)
private String genero;
@Column(name = "ute_naturalidade", nullable = false, length = 50)
private String naturalidade;
@Column(name = "ute_bi", length = 13, nullable = false, unique = true)
private String numeroBi;
@Column(name = "ute_nome_mae", length = 100)
private String nomeMae;
@Column(name = "ute_nome_pai", length = 100)
private String nomePai;
@Column(name="ute_local_trabalho", length = 50)
private String localTrabalho;
@Column(name = "ute_contacto", length = 9)
private String contacto;
@Column(name="ute_estado")
private String estado;
@Column(name = "ute_numero_emps")
private Long numeroEmprestimos;
@Column(name = "ute_data_registo", nullable = false)
private LocalDateTime dataRegisto;
@ManyToOne
@JoinColumn(name = "ute_instituicao_id")
private InstituicaoEnsino instituicaoEnsino;
@JoinColumn(name = "ute_endereco_id")
@OneToOne(cascade = CascadeType.ALL)
private Endereco endereco;
@OneToMany(mappedBy = "utenteEmprestimo")
private List<Emprestimo> emprestimos;
@OneToMany(mappedBy = "utenteDevolucoes")
private List<Devolucao> devolucoes;
public List<Devolucao> getDevolucoes() {
return devolucoes;
}
public void setDevolucoes(List<Devolucao> devolucoes) {
this.devolucoes = devolucoes;
}
public InstituicaoEnsino getInstituicaoEnsino() {
return instituicaoEnsino;
}
public void setInstituicaoEnsino(InstituicaoEnsino instituicaoEnsino) {
this.instituicaoEnsino = instituicaoEnsino;
}
public List<Emprestimo> getEmprestimos() {
return emprestimos;
}
public void setEmprestimos(List<Emprestimo> emprestimos) {
this.emprestimos = emprestimos;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public LocalDate getDataNascimento() {
return dataNascimento;
}
public void setDataNascimento(LocalDate dataNascimento) {
this.dataNascimento = dataNascimento;
}
public String getGenero() {
return genero;
}
public void setGenero(String genero) {
this.genero = genero;
}
public String getNaturalidade() {
return naturalidade;
}
public void setNaturalidade(String naturalidade) {
this.naturalidade = naturalidade;
}
public String getNumeroBi() {
return numeroBi;
}
public void setNumeroBi(String numeroBi) {
this.numeroBi = numeroBi;
}
public String getNomeMae() {
return nomeMae;
}
public void setNomeMae(String nomeMae) {
this.nomeMae = nomeMae;
}
public String getNomePai() {
return nomePai;
}
public void setNomePai(String nomePai) {
this.nomePai = nomePai;
}
public String getLocalTrabalho() {
return localTrabalho;
}
public void setLocalTrabalho(String localTrabalho) {
this.localTrabalho = localTrabalho;
}
public String getContacto() {
return contacto;
}
public void setContacto(String contacto) {
this.contacto = contacto;
}
public String getEstado() {
return estado;
}
public void setEstado(String estado) {
this.estado = estado;
}
public Long getNumeroEmprestimos() {
return numeroEmprestimos;
}
public void setNumeroEmprestimos(Long numeroEmprestimos) {
this.numeroEmprestimos = numeroEmprestimos;
}
public LocalDateTime getDataRegisto() {
return dataRegisto;
}
public void setDataRegisto(LocalDateTime dataRegisto) {
this.dataRegisto = dataRegisto;
}
public InstituicaoEnsino getInsEnsino() {
return instituicaoEnsino;
}
public void setInsEnsino(InstituicaoEnsino insEnsino) {
this.instituicaoEnsino = insEnsino;
}
public Endereco getEndereco() {
return endereco;
}
public void setEndereco(Endereco endereco) {
this.endereco = endereco;
}
}
@Entity
@Table(name = "liv_livro")
public class Livro{
@Id
@Column(name="liv_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "liv_titulo", nullable = false, length = 100)
private String titulo;
@Column(name = "liv_autor", nullable = false)
private String autor;
@Column(name = "liv_ano_edicao", length = 4)
private String anoEdicao;
@Column(name = "liv_edicao", length = 10)
private String edicao;
@Column(name = "liv_editora", length = 50)
private String editora;
@Column(name = "liv_isbn", length = 20, unique = true)
private String isbn;
@Column(name = "liv_numero_pedidos")
private Long numeropedidos;
@ManyToOne
@JoinColumn(name = "liv_categoria_id")
private CategoriaLivro categoria;
@Column(name = "liv_data_registo")
private LocalDateTime dataRegisto;
@OneToMany(mappedBy = "livroEmprestimo")
private List<Emprestimo> emprestimos;
@OneToMany(mappedBy = "livroDevolucoes")
private List<Devolucao> devolucoes;
public List<Devolucao> getDevolucoes() {
return devolucoes;
}
public void setDevolucoes(List<Devolucao> devolucoes) {
this.devolucoes = devolucoes;
}
public List<Emprestimo> getEmprestimos() {
return emprestimos;
}
public void setEmprestimos(List<Emprestimo> emprestimos) {
this.emprestimos = emprestimos;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitulo() {
return titulo;
}
public void setTitulo(String titulo) {
this.titulo = titulo;
}
public String getAutor() {
return autor;
}
public void setAutor(String autor) {
this.autor = autor;
}
public String getAnoEdicao() {
return anoEdicao;
}
public void setAnoEdicao(String anoEdicao) {
this.anoEdicao = anoEdicao;
}
public String getEdicao() {
return edicao;
}
public void setEdicao(String edicao) {
this.edicao = edicao;
}
public String getEditora() {
return editora;
}
public void setEditora(String editora) {
this.editora = editora;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public Long getNumeropedidos() {
return numeropedidos;
}
public void setNumeropedidos(Long numeropedidos) {
this.numeropedidos = numeropedidos;
}
public CategoriaLivro getCategoria() {
return categoria;
}
public void setCategoria(CategoriaLivro categoria) {
this.categoria = categoria;
}
public LocalDateTime getDataRegisto() {
return dataRegisto;
}
public void setDataRegisto(LocalDateTime dataRegisto) {
this.dataRegisto = dataRegisto;
}
}
Como devo resolver o meu problema?