-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with Many-to-one association and deletion
PostPosted: Thu Feb 10, 2011 10:04 am 
Newbie

Joined: Thu Feb 04, 2010 7:55 am
Posts: 2
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.