Hello,

How can I define the annotation in the following situation?


  | class User {
  | @ManyToMany(fetch = FetchType.EAGER, 
  |                     targetEntity=Role.class)
  |     @JoinTable(
  |         name="USER_ROLE_LINK",
  |         [EMAIL PROTECTED](name="username")},
  |         [EMAIL PROTECTED](name="rolename")}
  |     )
  |     public Collection<Role> getRoles() {
  |             return roles;
  |     }
  | 
  | }
  | 


  | class Role {
  | @ManyToMany(
  |             targetEntity=GenericUser.class,
  |             mappedBy="roles",
  |             fetch = FetchType.EAGER)
  |     @JoinTable(
  |         name="USER_ROLE_LINK",
  |         [EMAIL PROTECTED](name="rolename")},
  |         [EMAIL PROTECTED](name="username")}
  |     )
  |     @XmlElement
  |     public Collection<User> getUsers() {
  |             return users;
  |     }
  | 
  | }
  | 


The above two classes will create three tables (USER, ROLE, USER_ROLE_LINK) in 
database.


when I tried to delete the USER, it will delete one record from table 
USER_ROLE_LINK and USER. It is correct. But when I tried to delete one record 
from ROLE, it raised some exception: [B]something like cannot delete or update 
parent entity ...[/B].

How can I define the annotations so that when I want to remove an entity from 
USER and ROLE, it also can remove all the related records in USER_ROLE_LINK;

for example,

USER
=====
user1
user2


ROLE
====
role1
role2


USER_ROLE_LINK
============
user1      role1
user1      role2
user2      role1



In the above table records, if I want to delete 'user1', it should remove 
'user1' from USER and two records from USER_ROLE_LINK that are 'user1'

And if I want to remove 'role1', it will remove 'role1' from ROLE and two 
records from USER_ROLE_LINK that are 'role1'.






View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4170210#4170210

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4170210
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to