I tried many methods on the net, but it doesn't work.
I want to delete data from a database using hibernate, but I get this errors
SEVERE: Cannot delete or update a parent row: a foreign key constraint fails (sakila.comanda, CONSTRAINT comanda_ibfk_1 FOREIGN KEY (IDPRODUS) REFERENCES produs (IDPRODUS))
SEVERE: Could not synchronize database state with session
comanda means order and produs means product
Here is the code:
private void StergeButtonActionPerformed(java.awt.event.ActionEvent evt) {
try{
org.hibernate.Transaction tx = session.beginTransaction();
int idprodus = ((Produs)IdProdusComboBox.getSelectedItem()).getIdprodus();
Produs produs = (Produs) session.get(Produs.class, idprodus);
session.delete(produs);
tx.commit();
}catch(Exception e){
System.out.println(e.getMessage());
}
}