5 Replies Latest reply on Jan 2, 2008 7:02 AM by Max Rydahl Andersen

    seam-gen : reverse DB : many-to-many convention ?

    Damien Huriet Newbie

      Hi !

      I'm trying to find the convention to use so that seam-gen generates a many-to-many relationship.

      I'm using seam 2.0 in Eclipse Europa and JBossTools.
      My DB is in MySQL 5.0.
      The wizards to "generate entities" from an existing DB works very well.

      I'have understood that there is a convention to name the link table to preform the many-to-many relationship between two other tables,
      but I could not find a precise description of it.

      What name should I give to this link table ?
      Is there other thing than the name to do ?

      Thanks in advance !
      And thanks JBoss and all the contributers for their great job about Seam !
      It rocks !

      Damien

        • 1. Re: seam-gen : reverse DB : many-to-many convention ?
          Pete Muir Master

          seam-gen doesn't support many-to-many relationships.

          • 2. Re: seam-gen : reverse DB : many-to-many convention ?
            Damien Huriet Newbie


            Hello,

            Thanks for the reply, but it "seams" to do.
            Indeed, I've managed to generate a many-to-many relationship with seam-gen between two tables NAME1 and NAME2:

            The many-to-many relationship table should:
            - its name should be "NAME1_NAME2"
            - it has the right to have only 2 columns : a double primary key relying on the two foreignKey columns : FK1 and FK2 named as you want but with reference integrity constraints towards the primary key of the two tables : NAME1 and NAME2.

            It has generated me the getters and setters of the list in each entity NAME1 and NAME2 :

            Expl :

            - The class NAME1 contains the function "public Set<NAME2> getName2s()" and its setter

            and

            - The class NAME2 contains the function "public Set<NAME1> getName1s()" and its setter

            and no entity has been generated for the table "NAME1_NAME2", that is right because it is a "utility table" and not a table reflecting a "business objet" to be persisted.

            The hibernate relationship has been created also :

            @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
             @JoinTable(name = "NAME1_NAME2", catalog = "mycatalogname", joinColumns = { @JoinColumn(name = "NAME1_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "NAME2_ID", nullable = false, updatable = false) })
             public Set<Name2> getName2s() {
             return this.name2s;
             }
            
             public void setName2s(Set<Name2> name2s) {
             this.name2s = name2s;
             }
            


            I still have a problem in the following step :

            As the returned list is of type java.util.Set and not java.util.List, I do not (for the moment) manage to display this list in a rich:datatable :

             <rich:dataTable var="name2s"
             value="#{name1Home.instance.name2s}"
             rendered="#{name1Home.instance.name2s != null}"
             rowClasses="rvgRowOne,rvgRowTwo"
             id="name2sTable">
             <h:column>
             <f:facet name="header">id</f:facet>
             #{name2s.id}
             </h:column>
            


            Caused by javax.servlet.ServletException with message: "/Name1Edit.xhtml: Property 'id' not found on type org.hibernate.collection.PersistentSet"
            javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)


            Caused by javax.el.ELException with message: "/Name1Edit.xhtml: Property 'id' not found on type org.hibernate.collection.PersistentSet"
            com.sun.facelets.compiler.TextInstruction.write(TextInstruction.java:48)
            com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39)
            org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:280)


            If anyone can help me on this point.

            Thanks,

            Damien


            • 3. Re: seam-gen : reverse DB : many-to-many convention ?
              Pierre Raoul Novice

              I haven't try to use seam-gen to generate many-to-many relationship from DB.
              But I use the new generate-ui target to do it from existing classes.
              It needs changes not only in view templates (view, list and edit.xhtml.ftl) but also in EntityHome.java.ftl.

              About M2M and reverse DB: you should be able to find a old thread in jira where the seam team discussed this issue

              • 4. Re: seam-gen : reverse DB : many-to-many convention ?
                Pete Muir Master

                When I say doesn't support, perhaps what I mean is "isn't garunteed to do it correctly". I believe it works fine in Hibernate Tools (the reveng from db part) but not in generating the UI as atao says.