I'll share a solution with you.
You'll just need to set some details like field names to get the get and set and the hashcode and equals methods of the 4 classes
Class Item
@Entity
@Table(name = "item")
public class Item {
@Id
@Column(name = "item_id", length = 20, precision = 0)
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "descricao")
private String descricao;
//implementar os metodos corretamente hashCode equals, recomendavel
}
Supplier Class
@Entity
@Table(name = "forncedor")
public class Fornecedor {
@Id
@Column(name = "forncedor_id", length = 20, precision = 0)
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "nome")
private String nome;
//implementar os metodos corretamente hashCode equals, recomendavel
}
Relationship class, relationship fields must be equal and more Must be equal to table's DDL
@Table(name = "item_fornecedor")
@IdClass(ItemFornecedorPk.class)
public class ItemFornecedor {
private ItemFornecedorPk pk;
@Id
@ManyToOne
@JoinColumn(name = "item_id_pk", referencedColumnName = "id")
private Item item;
@Id
@ManyToOne
@JoinColumn(name = "forncedor_id_pk", referencedColumnName = "id")
private Fornecedor fornecedor;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "campoSoDaRelacao")
private Date campoSoDaRelacao;
//implementar os metodos corretamente hashCode equals, obrigatório
}
Relationship key class
@Embeddable
public class ItemFornecedorPk {
@Id
@ManyToOne
@JoinColumn(name = "forncedor_id_pk", referencedColumnName = "forncedor_id", insertable = false, updatable = false)
private Fornecedor fornecedor;
@Id
@ManyToOne
@JoinColumn(name = "item_id_pk", referencedColumnName = "item_id", insertable = false, updatable = false)
private Item item;
//implementar os metodos corretamente hashCode equals, obrigatório
}
Now it's put to the factory or the pesistyUnit read and it already works. of doing the lists also in the father of each one, but there only if it needs.