ManyToMany bidirectional deletion [message #640753] |
Tue, 23 November 2010 01:56 |
Brendan Haverlock Messages: 46 Registered: July 2009 |
Member |
|
|
Hi guys,
I have a relatively straight-forward problem. I have two classes: user and security role. Users have security roles and security roles have users.
In the User class I have the following:
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE})
@JoinTable(name = "person_security_role",
joinColumns = {@JoinColumn(name = "person_key")},
inverseJoinColumns = {@JoinColumn(name = "security_role_key")})
private List<SecurityRole> securityRoles;
In the SecurityRole class I have the following:
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE}, mappedBy = "securityRoles")
private List<User> users;
Now when I run the following test code I get two lists with different sizes:
User user = new User();
SecurityRole securityRole = new SecurityRole();
user.addSecurityRole(securityRole);
user = sb.updateFlush(user);
securityRole = user.getSecurityRoles().get(0);
user.getSecurityRoles().remove(0);
user = sb.updateFlush(user);
int userSecurityRolesSize = user.getSecurityRoles().size();
int securityRoleUsersSize = em.find(SecurityRole.class, securityRole.getSecurityRoleKey()).getUsers().size();
The list of users on the SecurityRole object has a size of 1, and the list of securityRoles on the user has the size of 0.
How do I make it so Eclipselink goes out and deletes the orphan from the list on the other side of the relationship without having to go over there and delete it myself?
Thanks!
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02617 seconds