0 Replies Latest reply on Jan 27, 2010 12:04 PM by goschan

    ManyToMany joint table mapping

    goschan

      Hello


      I have two tables, Supplier and Address, one supplier can have many addresses and one address can be shared by many suppliers. So in my schema I have a join table lk supplier address.


      Seam gen generated the two entity Supplier and Address :


      Supplier entity


      [...]
      private Set<Address> addresses = new HashSet<Address>(0);
      [...]
      
      @ManyToMany(fetch = FetchType.LAZY)
      @JoinTable(name = "lk_supplier_address", schema = "orderformschema", joinColumns = { @JoinColumn(name = "lk_fa_supplier_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "lk_fa_address_id", nullable = false, 
      updatable = false) })
           public Set<Address> getAddresses() {
                return this.addresses;
           }
      
           public void setAddresses(Set<Address> addresses) {
                this.addresses = addresses;
           }




      Address entity


      [...]
      private Set<Supplier> suppliers = new HashSet<Supplier>(0);
      [...]
      
      @ManyToMany(fetch = FetchType.LAZY)
      @JoinTable(name = "lk_supplier_address", schema = "orderformschema", joinColumns = { @JoinColumn(name = "lk_fa_address_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "lk_fa_supplier_id", nullable = false, updatable = false) })
           public Set<Supplier> getSuppliers() {
                return this.suppliers;
           }
      
           public void setSuppliers(Set<Supplier> suppliers) {
                this.suppliers = suppliers;
           }



      That seams right to me, but in the view, how can I access these two properties lk fa address id and lk fa supplier id.


      I try to modify the view generated by seam :




      <rich:dataTable value="#{supplierHome.instance.addresses}"
           var="_lkSupplierAddress"
           rendered="#{not empty supplierHome.instance.addresses}"
           rowClasses="rvgRowOne,rvgRowTwo" id="lkSupplierAddressesTable">
           <rich:column sortBy="#{_lkSupplierAddress.idAdd}">
                <f:facet name="header">Lk fa address id</f:facet>
                <h:outputText value="#{_lkSupplierAddress}" />
           </rich:column>
           <rich:column sortBy="#{_lkSupplierAddress.suppliers}">
                   <f:facet name="header">Lk fa supplier id</f:facet>
                <h:outputText value="#{_lkSupplierAddress}" />
           </rich:column>
      </rich:dataTable>



      But in this case I access to the HashSet addresses, right ? And Jboss write




      17:43:53,698 ERROR [viewhandler] Error Rendering View[/Supplier.xhtml]
      javax.faces.FacesException: javax.el.PropertyNotFoundException: /Supplier.xhtml @258,60 value="#{_lkSupplierAddress.idAdd}": Property 'idAdd' not found on type org.hibernate.collection.PersistentSet





      I'm a little bit lost :(


      If I remove the idApp from the var lkSupplierAddress, my DataTable show


      com.orderform.entity.Address@1bed987


      as it was a Address Object ...


      Can you explain me why ? Thanks


      Benjamin