-
1. Re: seam-gen and multiple foreign keys (again)
jayantada Sep 20, 2008 4:28 AM (in response to adrianflynn)In case you are getting compile errors because of duplicate defintions, I used the following to modify the template EntityHome.java.ftl in seamgen directory.
public class ${entityName}Home extends ${pojo.importType("org.jboss.seam.framework.EntityHome")}<${entityName}>
{
<#assign prevEntry = " ">
<#foreach property in pojo.allPropertiesIterator>
<#if c2h.isManyToOne(property)>
<#assign parentPojo = c2j.getPOJOClass(cfg.getClassMapping(property.value.referencedEntityName))>
<#assign parentHomeName = util.lower(parentPojo.shortName) + "Home">
<#if parentHomeName !=prevEntry>
@${pojo.importType("org.jboss.seam.annotations.In")}(create=true)
${parentPojo.shortName}Home ${parentHomeName};
<#assign prevEntry = parentHomeName>
</#if>
</#if>
</#foreach>
A quick & dirty solution but got tired of fixing manually -
2. Re: seam-gen and multiple foreign keys (again)
adrianflynn Sep 20, 2008 4:36 PM (in response to adrianflynn)Thank you for the suggestion, Jayanta, and your code does indeed prevent the compilation errors in the FlightHome class, however the resulting application permits CRUD operations to be performed on the departureAirport field of a Flight, but there is no means to access the destinationAirport.
I believe that the original structure showing both fields in the Home class annoted with @In, but with different names is a more correct starting point:
@In(create = true) AirportHome departureAirportHome; @In(create = true) AirportHome destinationAirportHome;
The wire() method also needs manual modification to make this work.
However, I am lost as to what changes are required in the .pages.xml and .xhtml files.
I suspect that Flight.page.xml will need the following two lines duplicated and renamed:
<param name="airportFrom"/> <param name="airportId" value="#{airportHome.airportId}"/>
The Flight.xhtml page seems ok but I can't see any way to avoid duplicating all eight
Airport files in my source tree:- Airport.page.xml
- Airport.xhtml
- AirportEdit.page.xml
- AirportEdit.xhtml
- AirportList.page.xml
- AirportList.xhtml
- AirportHome.java
- AirportList.java
... with the only difference being the @Name Annotations in the java files, and renaming the links in the destinationAirport tab of the Flight.xhtml to use the new component name eg Airport2
While class re-use is common in 'ordinary' Java, I cannot find any examples of it being used in Seam.
Can anyone advise me please?
Thanks
Adrian
-
3. Re: seam-gen and multiple foreign keys (again)
atao Sep 21, 2008 12:38 PM (in response to adrianflynn)Adrian,
The patch proposed (doublon.zip and doublon2.patch) for JBSEAM-994 works. And it does the job automatically.
If you want to do it manually, you can still check how the patch does the job. Yes, there are quite a lot of code to add. Mainly to deal with one seam component per attribute of same type.