[jboss-user] [EJB 3.0] - Update for entities with oneToMany relatinship not working p

mohali do-not-reply at jboss.com
Wed Aug 22 14:42:51 EDT 2007


I have two entites User and Permissions with one to many relationship as below. In UserEntity ejb I have this code:

@OneToMany(mappedBy = "user", cascade = {CascadeType.PERSIST, CascadeType.MERGE})
  |     public List<PermissionEntityEJB> getPermissions() {
  |         return this.permissions;
  |     }
  | 

And on permissions entity ejb I  have this code for relationship:

 @ManyToOne
  |     @JoinColumn(name = "USER_ID", nullable = false)
  |     public UserEntityEJB getUser() {
  |         return this.user;
  |     }
  | 

When I try to update the user's permissions I create a list of  PermissionsEntity objects (that includes setting the user attribute to the current User Entity ejb) and then call the setter on User Entity ejb using syntax like below:


  | usrEntity.setPermissions(permissionsList)
  | 

After the committing of transaction in the database I see a new set permissions added on the user's current permissions. I was expecting to see in the database only the new set of permissions (the current/old set of permissions should have been deleted). Am I seeing the expected behavior or Am I doing something wrong or my relationship setup is not ok. Do I need to explicitly delete the current/old permissions myself before adding the new set of permissions?

-Navjeet


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

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4077006



More information about the jboss-user mailing list