-->
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: Constraints/Cascade-delete on jointable using OneToMany
PostPosted: Wed Feb 11, 2009 4:58 am 
Newbie

Joined: Wed Feb 11, 2009 4:49 am
Posts: 1
Howdy,

I've got a OneToMany using a join table, which looks something like this:

Code:
    @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
    @JoinTable(name="JOIN_TABLE", joinColumns = { @JoinColumn( name="A_ID") },
            inverseJoinColumns = @JoinColumn( name="B_ID")
    )
    private Collection<B> bCollection;


Hibernate then generates the following table:

Code:
    create table JOIN_TABLE (
        A_ID number(19,0) not null,
        B_ID number(19,0) not null,
        unique (B_ID)
    );
    alter table JOIN_TABLE
        add constraint FKB8D1C3F47CD39FA9
        foreign key (B_ID)
        references Bs;

    alter table JOIN_TABLE
        add constraint FKB8D1C3F43659D060
        foreign key (A_ID)
        references As;


Now, when I try to delete an object of type B, I get a big fat SQL-exception thrown at me. This is pretty obvious, considering deleting B would violate the constraint. I essentially need an "ON DELETE CASCADE" on that constraint. All the annotation configurations I've been able to find so far seem to focus on deleting the parents and children, which is not what I want here. When I delete an object of type B, I just want it to essentially be removed from any collections -- ie removing it from the join table.

Am I missing something really obvious here?

Thanks a bunch!

Using Hibernate 3.2.5


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.