Boa tarde Pessoal,
Estou utilizando um método GET para um formalário, mas estou tendo como retorno o seguinte erro:
org.springframework.beans.NotReadablePropertyException: Invalid property 'deliverables' of bean class [br.com.rs.model.Report]: Bean property 'deliverables' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
Controller
@GetMapping("/terms")
public ModelAndView terms() {
ModelAndView modelAndView = new ModelAndView("pages/terms");
modelAndView.addObject("report", new Report());
modelAndView.addObject("reports", reportService.findAll());
modelAndView.addObject("deliverables", deliverableRepository.findAll());
modelAndView.addObject("documents", documentRepository.findAll());
return modelAndView;
}
Repository
@Repository("deliverableRepository")
public interface DeliverableRepository extends JpaRepository<Deliverable, Long> {
}
Models
@Entity
@Table(name = "report")
public class Report {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String client;
@DateTimeFormat(pattern = "yyyy-MM-dd")
@Temporal(TemporalType.DATE)
private Calendar homolog;
private String contact;
@ManyToOne
private User user;
@DateTimeFormat(pattern = "yyyy-MM-dd")
@Temporal(TemporalType.DATE)
private Calendar golive;
private String id_crm;
@ManyToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE})
@JoinTable(name = "report_deliverable", joinColumns = @JoinColumn(name = "report_id"), inverseJoinColumns = @JoinColumn(name = "deliverable_id"))
// Motivo de usar set: https://vladmihalcea.com/the-best-way-to-use-the-manytomany-annotation-with-jpa-and-hibernate/
private Set<Deliverable> deliverables = new HashSet<>();
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getClient() {
return client;
}
public void setClient(String client) {
this.client = client;
}
public Calendar getHomolog() {
return homolog;
}
public void setHomolog(Calendar homolog) {
this.homolog = homolog;
}
public String getContact() {
return contact;
}
public void setContact(String contact) {
this.contact = contact;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Calendar getGolive() {
return golive;
}
public void setGolive(Calendar golive) {
this.golive = golive;
}
public String getId_crm() {
return id_crm;
}
public void setId_crm(String id_crm) {
this.id_crm = id_crm;
}
public void addDeliverable(Deliverable deliverable) {
deliverables.add(deliverable);
deliverable.getReports().add(this);
}
public void removeDeliverable(Deliverable deliverable) {
deliverables.remove(deliverable);
deliverable.getReports().remove(this);
}
}
@Entity
@Table(name = "deliverable")
public class Deliverable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String deliverable;
@ManyToMany(mappedBy = "deliverables")
private Set<Report> reports = new HashSet<>();
public Deliverable() {}
public Deliverable(String deliverable) {
this.deliverable = deliverable;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getDeliverable() {
return deliverable;
}
public void setDeliverable(String deliverable) {
this.deliverable = deliverable;
}
public Set<Report> getReports() {
return reports;
}
public void setReports(Set<Report> reports) {
this.reports = reports;
}
}
Select onde gera o erro:
<select class="form-control select2 select2-hidden-accessible" th:field="*{deliverables}" multiple="" data-placeholder="Selecione os entreg�veis" style="width: 100%;" tabindex="-1" aria-hidden="true">
<option th:each="deliverable : ${deliverables}" th:text="${deliverable.deliverable}" th:value="${deliverable.id}" ></option>
</select>