2 Replies Latest reply on Dec 13, 2004 5:27 PM by bill.burke

    ManytoMany Mappings - Idnetity Column Requirement

    mduffy_lists

      The ManytoMany mapping appears to work fine, as long as you use the identity columns in your mapping table. The example below works:


      @ManyToMany(cascade = {CascadeType.MERGE, CascadeType.MERGE}, fetch = FetchType.EAGER)
      @AssociationTable(table = @Table(name = "tbl_userRoleMapping"),
      joinColumns = {@JoinColumn(name = "userID")},
      inverseJoinColumns = {@JoinColumn(name = "roleTypeID")})
      public Set getRoleTypes() {
      return roleTypes;
      }

      However, if you use columns in your mapping table that are not identity columns, you get a null collection back. The example below does not work:

      @ManyToMany(cascade = {CascadeType.MERGE, CascadeType.MERGE}, fetch = FetchType.EAGER)
      @AssociationTable(table = @Table(name = "tbl_userRoleMapping"),
      joinColumns = {@JoinColumn(name = "username")},
      inverseJoinColumns = {@JoinColumn(name = "roleTypelabel")})
      public Set getRoleTypes() {
      return roleTypes;
      }

      In the EJB 3.0 spec, "10.1.16 ManyToMany Annotation", it does not say anything about the requirement for the columns in the mapping table to be identity columns.

      Does anyone know what position JBoss has on the requirement for the mapping coluns to be identity columns?

      Thx.

      Mike