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