Hi all,
I'm trying to model a foreign key reference with cascading delete. I have the Classes
User, List and ListEntry. ListEnry belongs to an instance of List and references an
Instance of User. User does not know anything about ListEntry.
I want to make sure, that when a User is deleted, all referencing ListEntries will be
deleted too. The Other way round, deleting a ListEntry should not have any affect on the
referenced User or List.
In classic ER-Modeling I would have used something like this:
create Table user(String id, String name, ...)
create Table ListEntry(
String id,
String user references user.id on delete cascade,
String list references List.id on delete cascade)
create Table List(String id, String name)
Everything would be perfect in this ER world. With EJB3 i would expect to use the
following:
@Entity
| class User{
|
| @Id
| String id
|
| String name
|
| }
|
|
| @Entity
| class ListEntry{
|
| @Id
| String id
|
| User user
|
| @ManyToOne(cascade=CascadeType.REMOVE)
| User getUser(){
| ..}
|
| void setUser(User user){
| }
|
| }
|
| @Entity
| class List{
| @Id
| String id
|
| List<ListEntry> entries;
|
| @OneToMany(cascade=CascadeType.ALL)
| List<ListEntry> getEntries(){
| ...
| }
|
| void setEntries(List<ListEntry> entries){
| ...
| }
|
| }
|
I tried this but it didn't work quite as I expected. Deleting a ListEntry results in a
delete of the Referenced User too...
How would I model the above Problem? I'm puzzled.
Thanks for advice
Juergen
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3979117#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...