Hello, I'm having a problem saving data to a last table. Well, this table has two foreign keys and the same ones are primary keys:
WhengoingtotheController,savethetable,Iusethefollowingcodes:
itv.setId();itv.setIngresso(ing);itv.setVenda(ven);itv.setItvqtde(Integer.valueOf(request.getParameter("txtqtde")));
itvDao.salvarItemVenda(itv);
response.sendRedirect("my-tickents-buy.jsp");
Here is my ItemVendaDao:
public void salvarItemVenda(ItemVenda itv){
try {
s = new ConnectionFactory().getSessionFactory();
tx = s.beginTransaction();
s.save(itv);
tx.commit();
s.close();
JOptionPane.showMessageDialog(null, "Item venda salva com sucesso");
} catch (Exception e) {
tx.rollback();
JOptionPane.showMessageDialog(null, "Erro ao salvar item venda" +e.getMessage());
s.close();
}
}
What do I need to put in itv.setId ()? When mapping it creates this method to save the Id of the sales item, where the ID of the sales item are two: the object of the ticket and the object of the sale, both are already being saved above with the code:
itv.setIngresso(ing);
itv.setVenda(ven);
Again, what do you need to put in itv.setId () ?
Here is ItemVenda.java (mapped automatically by hibernate)
public class ItemVenda implements java.io.Serializable {
private ItemVendaId id;
private Ingresso ingresso;
private Venda venda;
private int itvqtde;
public ItemVenda() {
}
public ItemVenda(ItemVendaId id, Ingresso ingresso, Venda venda, int itvqtde) {
this.id = id;
this.ingresso = ingresso;
this.venda = venda;
this.itvqtde = itvqtde;
}
public ItemVendaId getId() {
return this.id;
}
public void setId(ItemVendaId id) {
this.id = id;
}
public Ingresso getIngresso() {
return this.ingresso;
}
public void setIngresso(Ingresso ingresso) {
this.ingresso = ingresso;
}
public Venda getVenda() {
return this.venda;
}
public void setVenda(Venda venda) {
this.venda = venda;
}
public int getItvqtde() {
return this.itvqtde;
}
public void setItvqtde(int itvqtde) {
this.itvqtde = itvqtde;
}
And the SalesId.java Item is as follows:
public class ItemVendaId implements java.io.Serializable {
private int itvvencodigo;
private int itvingressocodigo;
public ItemVendaId() {
}
public ItemVendaId(int itvvencodigo, int itvingressocodigo) {
this.itvvencodigo = itvvencodigo;
this.itvingressocodigo = itvingressocodigo;
}
public int getItvvencodigo() {
return this.itvvencodigo;
}
public void setItvvencodigo(int itvvencodigo) {
this.itvvencodigo = itvvencodigo;
}
public int getItvingressocodigo() {
return this.itvingressocodigo;
}
public void setItvingressocodigo(int itvingressocodigo) {
this.itvingressocodigo = itvingressocodigo;
}