2

Bom dia.

Estou com dificuldades em realizar uma consulta na base de dados onde minha entidade Employee tem 2 mapeamentos @ManyToMany e 1 mapeamento @ManyToOne. Ao realizar uma consulta os dados de Employee e Projects são retornados sem maiores problemas. Os atributos relacionais do ManyToMany que está sendo um problema. Para fazer a inserção está ocorrendo ok. Para buscar na base um problema. Alguém pode ajudar por gentileza? Obrigado

@Entity
@Table(name = "employee")
@JsonView
public class Employee implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id_employee;

    @NotNull
    @Column(name = "name", length = 120)
    private String name;

    @NotNull
    @Column(name = "role", length = 100)
    private String role;

    @NotNull
    private Double salary;

    @NotNull
    @Column(name = "manager", length = 120)
    private String manager;

    private int gcm;

    @NotNull
    @ManyToOne
    private Projects project;

    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinTable(name = "employee_skill",
        joinColumns = @JoinColumn(name = "id_employee"),
        inverseJoinColumns = @JoinColumn(name = "id_skill")
    )

    private List<Skill> skill;

    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "employee_certification",
        joinColumns = @JoinColumn(name = "id_employee"),
        inverseJoinColumns = @JoinColumn(name = "id_certification")
    )

    private List<Certification> certification;
}

Classe skill

@Entity
@Table(name = "skill")
@JsonView
public class Skill implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id_skill;

    @NotNull
    private String descricao;

    @ManyToMany(mappedBy = "skill", fetch = FetchType.LAZY)
    private List<Employee> employee;

    public Skill(){}
}

Classe certification

@Entity
@Table(name = "certification")
@JsonView
public class Certification implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id_certification;

    @NotNull
    private String descricao;

    @ManyToMany(mappedBy = "certification", cascade = CascadeType.ALL)
    private List<Employee> employee;

    public Certification(){}

    public Certification(String descricao){
        this.descricao = descricao;
    }
}

Classe projects

@Entity
@Table(name = "projects")
@JsonView
public class Projects implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id_project;

    @Column(name = "name", length = 150)
    private String name;

    @Column(name = "customer", length = 100)
    private String customer;

    private Double valueOfProject;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "dt_Begin")
    private Calendar dtBegin;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "dt_End")
    private Calendar dtEnd;

    @OneToMany(mappedBy = "project")
    private List<Employee> employee;

    public Projects(){}

}
1
  • Poderia postar na resposta, onde vc faz a chama da Employe e qual seria os erros ocorrido 17/01/2019 às 17:00

1 Resposta 1

0

Fazendo um exemplo das classes Certification e Employee, acredito que isso possa ajudar:

List<Certification> findByEmployee_Name(String name);

Outro exemplo passando uma lista de nomes:

 List<Certification> findByEmployee_NameIn(List<String> name);
9
  • O que eu desejo Kaique é que quando eu busque todos os Employee cadastrados, que retorne junto as skill dele e as certificações que ele possui
    – Claudio
    22/12/2018 às 13:48
  • Ao fazer um debug deu o seguinte erro:
    – Claudio
    22/12/2018 às 13:54
  • 2018-12-22 11:51:32.069 WARN 6064 --- [nio-8080-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Failure while trying to resolve exception [org.springframework.http.converter.HttpMessageNotWritableException] java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
    – Claudio
    22/12/2018 às 13:54
  • você consegue executar List<Employee> findAll()? Da interface CrudRepository 22/12/2018 às 14:00
  • Consigo sim, porém ocorre o erro acima.
    – Claudio
    22/12/2018 às 14:02

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .