0 Replies Latest reply on Mar 14, 2007 10:12 AM by Nicola Ben

    ManyToMany problem: removing referenced records

    Nicola Ben Novice

      Hi,
      I am working with ManyToMany annotation and I cannot obtain the behaviour I'd like to. I need for this forum's help.

      I have these tables:

      SkillTypes:
      id_skill_type
      ...


      Operations:
      id_operation
      ...


      R_operations_skills:
      id_r_operation_skill PK
      id_operation FK
      id_skill_type FK


      In my 2 entity beans (I don't have a EJB for the relation table R_operations_skills) I used these annotations:

      Operation.java

      @ManyToMany(cascade={CascadeType.REFRESH, CascadeType.PERSIST}, fetch=FetchType.LAZY)
       @JoinTable(name="r_operations_skills",
       joinColumns=@JoinColumn(name="id_operation"),
       inverseJoinColumns=@JoinColumn(name="id_skill_type"))
       @OrderBy("description")
       public List<SkillType> getSkillTypes() {
       return skillTypes;
       }
      




      SkillType.java

      @ManyToMany(cascade={CascadeType.REFRESH, CascadeType.PERSIST}, fetch=FetchType.LAZY)
       @JoinTable(name="r_operations_skills",
       joinColumns=@JoinColumn(name="id_skill_type"),
       inverseJoinColumns=@JoinColumn(name="id_operation"))
       @OrderBy("description")
       public List<Operation> getOperations() {
       if(operations == null) {
       operations = new ArrayList<Operation>();
       }
       return this.operations;
       }



      My problem is that deleting a skill which has relations with operations, the skill is removed from SkillTypes and also records in the relation table are deleted.
      I exptected that I cannot delete a skillType used in the relation.
      Could you please suggest me how to solve my problem?

      Thank u
      Nico