0
Could someone ask me some questions about Ibernate? Good have 2 product and sales tables with a n:n relationship that generated an item_sale table
I did it in my two models to map:
Class Products:
@Entity(name="Produtos")
@Table(name = "produtos")
public class Produtos {
@Id
@GeneratedValue
private Long codProduto;
@Column(name="preco_Venda")
private Double preco_Venda;
@Column(name="nome")
private String nome;
}
the class Sale:
@Entity(name="Venda")
@Table(name = "venda")
public class Venda {
@Id
@GeneratedValue
private Long codVenda;
@Column(name="data_venda")
private Date dataVenda;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idCaixa")
private Caixa caixa;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name="produtos_idVenda", referencedColumnName="idVenda",nullable=false)
private List<Lista_Produtos> listaProdutos;
}
good i don’t need to have this my item_sell table as a class
one of my doubts is, with this mapping what I would need to insert a value in this item_sale table.
Another question is regarding my Products class:
Would I need a Sale composition? ex:
Private sale;
//
or I would need to create + an item_Venda class
// to illustrate my relationship in the database:
mt thanks bro!!
– Joao Spirit