-
1. Re: seam generate entities for many-to-many relationships
wouterhartog Jan 7, 2010 10:41 AM (in response to wouterhartog)Found the solution:
I had to define my UserRole table different.
I had one UserRoleID column as the primary key, and the userId and roleId as just FK to the other tables, like this:
userRoleId (PK)
roleId (FK)
userId (FK)
When I changed the table structure to this (removed the original PK column):
roleID (PK, FK)
userId (PK, FK)
seam generate entities worked as I wanted to: on the Entity class User, I had a @ManyToMany annotation, linking to the Role table, using the UserRole table as the joinTable.
a great tool!
-
2. Re: seam generate entities for many-to-many relationships
maxandersen Jan 7, 2010 11:21 AM (in response to wouterhartog)Yes, your solution is correct since otherwise we just see the tables are three related entities. No way to detect the many-to-many.
But to answer your question about convincing/controlling seam-gen (or rather hibernate tools) beyond what is in your database lookup rev-eng.xml in the documentation or google
-
3. Re: seam generate entities for many-to-many relationships
goschan Jan 26, 2010 5:12 AM (in response to wouterhartog)Hello,
yes the seam gen generates only two entity, but in the xhtml (supplier.xhtml in my case) view file, I have this :
<h:outputText value="There are no lkSupplierAddresses associated with this supplier."
rendered="#{empty supplierHome.lkSupplierAddresses}"/><rich:dataTable value="#{supplierHome.lkSupplierAddresses}"
var="_lkSupplierAddress"
rendered="#{not empty supplierHome.lkSupplierAddresses}"
rowClasses="rvgRowOne,rvgRowTwo"
id="lkSupplierAddressesTable">lkSupplierAddresses is my table with the two IDs as a primary key (suppId and addId), when I try to access this outputText, or dataTable I have this exception :
16:29:15,885 ERROR [viewhandler] Error Rendering View[/Supplier.xhtml]
javax.faces.FacesException: javax.el.PropertyNotFoundException: /Supplier.xhtml @66,77 rendered="#{empty supplierHome.lkSupplierAddresses}": Property 'lkSupplierAddresses' not found on type com.orderform.session.SupplierHome_$$_javassist_seam_11So there is a problem in the generation of the xhtml files.
Do you know is there is a fix for the generation files ftl ?
Thanks, Benjamin
-
4. Re: seam generate entities for many-to-many relationships
maxandersen Jan 26, 2010 1:52 PM (in response to goschan)That is better asked at the seam forums since we are simply using the seam-gen templates here - but I don't believe seam-gen ever supported many-to-many generation fullly.