I’ll share a solution with you.
You will only need to get a few details such as field names to do the get and set and hashcode and equals methods of the 4 classes
Item class
@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
}
Relation class, the relation fields must be equal and more Must be equal to the DDL of the table
@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
}
Class of the relationship key
@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 is put to the Factory or pesistyUnit read and it already works. da make the lists also in the father of each, but ai only if you need.
Is using Hibernate?
– novic
These annotations are provided as?
– user60096
I am not using JPA. What is the alternative solution?
– user60097