-
1. Re: seam-gen : reverse DB : many-to-many convention ?
pmuir Dec 18, 2007 4:33 PM (in response to damienhuriet)seam-gen doesn't support many-to-many relationships.
-
2. Re: seam-gen : reverse DB : many-to-many convention ?
damienhuriet Dec 19, 2007 2:56 AM (in response to damienhuriet)
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 ?
atao Dec 19, 2007 4:30 AM (in response to damienhuriet)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 ?
pmuir Dec 19, 2007 5:31 PM (in response to damienhuriet)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.
-
5. Re: seam-gen : reverse DB : many-to-many convention ?
maxandersen Jan 2, 2008 7:02 AM (in response to damienhuriet)exactly.