I've this bean with annotations (showing the relevant ones):
Code:
@Entity
@Table(name = "Prodotti")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Prodotto {
    int id;
    String codice;
    double prezzo;
    double prezzoCanone;
    String descrizione;
    String note;
    Prodotto prodottoDiRiferimento;
...
    @ManyToOne(cascade = CascadeType.REMOVE)
    public Prodotto getProdottoDiRiferimento() {
        return prodottoDiRiferimento;
    }
    public void setProdottoDiRiferimento(Prodotto prodottoDiRiferimento) {
        this.prodottoDiRiferimento = prodottoDiRiferimento;
    }
}
all mapped to mySQL.
If I do a delete of one of these beans that has a prodottoDiRiferimento property set to null and that other beans have as they prodottoDiRiferimento, I get:
Code:
java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails (`jacciseweb`.`prodotti`, CONSTRAINT `FKC803BB11ACD3B812` FOREIGN KEY (`prodottoDiRiferimento_ID`) REFERENCES `prodotti` (`ID`))
What I'd like is that all the beans that point to the deleted one with the prodottoDiRiferimento property would get deleted too.
Did I do this association the wrong way? What would be the best one?
How to do it?