4 Replies Latest reply on Aug 27, 2007 5:18 PM by Navjeet

    Update for entities with oneToMany relatinship not working p

    Navjeet Newbie

      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:

       @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:


      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?