3 Replies Latest reply on Oct 20, 2005 8:14 PM by Emmanuel Bernard

    ManyToMany relationship problem

    silviu.marcu Newbie

      Hi, I have a problem using many to many relationship:

      I have 3 classes:
      -----------------------------------------------
      A has: (1 relation with B)
      @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
      @JoinTable(table = @Table(name = "......"),
      joinColumns = {@JoinColumn(name = ".....")},
      inverseJoinColumns = {@JoinColumn(name = ".....")})
      public Collection getBs()
      -----------------------------------------------
      B has: (2 relations - A and C)
      @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE},
      fetch = FetchType.EAGER, mappedBy="bs")
      public Collection getAs()

      @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
      @JoinTable(table = @Table(name = "........"),
      joinColumns = {@JoinColumn(name = "...........")},
      inverseJoinColumns = {@JoinColumn(name = "........")})
      public Collection getCs()
      -----------------------------------------------
      C has:
      @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE},
      fetch = FetchType.EAGER, mappedBy="cs")
      public Collection getBs()
      ===================================
      The problem is : when I call A.getBs ... I receive a list of duplicates of B (like the selection of B's is not correctly joined)

      ex:
      a1 - b1 - c1
      - b1 - c11
      - b2 - c2

      The A.getBs RETURN b1, b1, b2 instead of b1, b2

      Thanks.