1 2 Previous Next 17 Replies Latest reply on Jun 1, 2007 10:24 PM by gavin.king

    seam-gen enhancement

    guanwh

      Would it be great that seam-gen will generate crud pages and classes for an existing Entity class,just like seam-gen generate the crud pages,classes and entity classes from database.

      Thanks

        • 1. Re: seam-gen enhancement
          maxandersen

          sure, and it is all possible just not enabled in seamgen yet.

          you can do it by have it use a [jpaconfiguration] instead of [jdbcconfiguration].... care to submit a patch ? :)

          • 2. Re: seam-gen enhancement
            guanwh

             

            "max.andersen@jboss.com" wrote:
            sure, and it is all possible just not enabled in seamgen yet.

            you can do it by have it use a [jpaconfiguration] instead of [jdbcconfiguration].... care to submit a patch ? :)

            Sure. I am not farmiliar with it but i will give it a try

            • 3. Re: seam-gen enhancement
              kentlam

              This is the solution I have to get seam-gen to work on existing entities:
              1) Either append the following target to the seam-gen/build.xml or just modify the generate-entities target:

              <target name="generate-domain" depends="validate-project"
               description="Generate based on existing domain entities">
              
               <taskdef name="hibernate"
               classname="org.hibernate.tool.ant.HibernateToolTask">
               <classpath>
               <fileset dir="lib">
               <include name="*.jar" />
               </fileset>
               <fileset dir="../hibernate/lib">
               <include name="*.jar" />
               </fileset>
               <pathelement path="${driver.jar}" />
               <pathelement path="../jboss-seam-gen.jar" />
               </classpath>
               </taskdef>
              
               <hibernate templatepath=".">
               <jpaconfiguration persistenceunit="testproject" />
               <classpath>
               <pathelement path="${project.home}/dist" />
               </classpath>
              
               <property key="hibernatetool.util.toolclass"
               value="org.jboss.seam.tool.Util" />
              
               <hbmtemplate filepattern="{class-name}List.xhtml"
               template="view/list.xhtml.ftl"
               destdir="${project.home}/view" />
               <hbmtemplate filepattern="{class-name}.xhtml"
               template="view/view.xhtml.ftl"
               destdir="${project.home}/view" />
               <hbmtemplate filepattern="{class-name}.page.xml"
               template="view/view.page.xml.ftl"
               destdir="${project.home}/view" />
               <hbmtemplate filepattern="{class-name}Edit.xhtml"
               template="view/edit.xhtml.ftl"
               destdir="${project.home}/view" />
               <hbmtemplate filepattern="{class-name}Edit.page.xml"
               template="view/edit.page.xml.ftl"
               destdir="${project.home}/view" />
               <hbmtemplate filepattern="{package-name}/{class-name}List.java"
               template="src/EntityList.java.ftl"
               destdir="${project.home}/src" />
               <hbmtemplate filepattern="{class-name}List.page.xml"
               template="view/list.page.xml.ftl"
               destdir="${project.home}/view" />
               <hbmtemplate filepattern="{package-name}/{class-name}Home.java"
               template="src/EntityHome.java.ftl"
               destdir="${project.home}/src" />
               <hbmtemplate filepattern="menu.xhtml"
               template="view/layout/menu.xhtml.ftl"
               destdir="${project.home}/view/layout" />
               </hibernate>
              
               <taskdef name="javaformatter"
               classname="org.hibernate.tool.ant.JavaFormatterTask">
               <classpath>
               <fileset dir="lib">
               <include name="*.jar" />
               </fileset>
               </classpath>
               </taskdef>
              
               <javaformatter>
               <fileset dir="${project.home}/src">
               <include name="**/*.java" />
               </fileset>
               </javaformatter>
              
               <echo
               message="Type 'seam restart' and go to http://localhost:8080/${project.name}" />
              
              </target>
              

              2) Run 'seam setup' and 'seam new-project' to generate the project skeleton

              3) create a 'dist' directory under the newly created project directory

              4) copy all your compiled classes for the domain model into the 'dist' directory

              5) copy all your src code for the domain model into the 'src' directory under the newly created project directory

              6) create a META-INF directory inside 'dist' directory

              7) copy the persistence-dev.xml from the resources directory in the newly created project to the dist/META-INF directory and rename it to persistence.xml

              8) Now change the persistenceunit under <jpaconfiguration .../> in the seam-gen/build.xml to match the persistentunit in the persistence.xml

              9) download the put the javassist.jar into your [Seam installation dir]/hibernate/lib directory

              10) run seam generate-domain (or seam generate-entities if you modify the ant target)


              • 4. Re: seam-gen enhancement
                gavin.king

                Would you please add a JIRA issue, named "generate application from existing entities", and link to this post.

                Thanks

                • 5. Re: seam-gen enhancement
                  saeediqbal1

                  Correct me if i am wrong. Isn't the functionality requested the same as seam generate-entities ? or maybe i misunderstood it. "data model"

                  • 6. Re: seam-gen enhancement
                    kentlam

                     

                    "saeediqbal1" wrote:
                    Correct me if i am wrong. Isn't the functionality requested the same as seam generate-entities ? or maybe i misunderstood it. "data model"


                    generate-entities uses <jdbcconfiguration ..../> which does a reverse engineering and creates the domain model from your database, while this solution will generate a CRUD application based on an EXISTING domain model.

                    • 7. Re: seam-gen enhancement
                      kentlam

                       

                      "gavin.king@jboss.com" wrote:
                      Would you please add a JIRA issue, named "generate application from existing entities", and link to this post.

                      Thanks


                      Done

                      http://jira.jboss.org/jira/browse/JBSEAM-843

                      • 8. Re: seam-gen enhancement
                        saeediqbal1

                        wow kentlam thanks for the information. I thought the seam command generated the CRUD ones and i was feeling happy i dont have to do the manual process of hibernate/crud generation from eclipse. ... hmm i was wrong.

                        • 9. Re: seam-gen enhancement
                          awhitford

                          Good work Kent! I can't wait to try this...

                          I can't stress how important this feature is because the reverse engineering approach makes a lot of incorrect assumptions. The Entity bean provides much richer information for CRUD generation.

                          Some problems that I have run into with reverse engineering include:


                          • I have run into problems dealing with Dates because the database (SQL Server) only has one date type (datetime) for dates, times, and timestamps. However, if you look at my Entity bean, it clearly has the field tagged with a Temporal annotation (@Temporal(TemporalType.DATE)).

                          • I have run into problems with Enumerated types. To the database, I often store enum values as Strings, so the reverse engineering makes the field a String rather than an enum. My Entity bean has an enum annotated (@Enumerated(EnumType.STRING)).

                          • I rarely override the columnDefinition (for an enum code or iso code, for example). The reverse engineering translates char(n) columns to be varchar(n), then deployment fails because Hibernate does some validation.

                          • Foreign Key constraints often creates unneccesary object coupling. For example, I have an Exchange object that has a ManyToOne relationship with a Country. Reverse engineering will create the Country object with a set of Exchanges. In truth, Country should not really know about its Exchanges, but an Exchange must know its Country.

                            Because of these problems, I am often only able to use Seam-gen as a very rough guide because it often doesn't yield a working solution. I definitely am not expecting perfection, but there is clearly an information gap due to reverse engineering that can be mitigated by using the Entity beans directly.

                            I recognize Seam-gen as an invaluable tool for Seam development. It has definitely saved me time, but this enhancement makes it 100 times more useful. I'm crossing my fingers for 1.1.7. ;-)


                          • 10. Re: seam-gen enhancement
                            gavin.king

                             

                            "saeediqbal1" wrote:
                            wow kentlam thanks for the information. I thought the seam command generated the CRUD ones and i was feeling happy i dont have to do the manual process of hibernate/crud generation from eclipse. ... hmm i was wrong.


                            Are you sure you've understood what he's really saying?

                            What seam-gen does is generate *everything* from the database schema.

                            What this stuff does is generate everything *except* for the @Entity beans from an existing set of @Entity beans.

                            • 11. Re: seam-gen enhancement
                              gavin.king

                               

                              "awhitford" wrote:
                              Good work Kent! I can't wait to try this...

                              I can't stress how important this feature is because the reverse engineering approach makes a lot of incorrect assumptions. The Entity bean provides much richer information for CRUD generation.

                              Some problems that I have run into with reverse engineering include:

                              • I have run into problems dealing with Dates because the database (SQL Server) only has one date type (datetime) for dates, times, and timestamps. However, if you look at my Entity bean, it clearly has the field tagged with a Temporal annotation (@Temporal(TemporalType.DATE)).

                              • I have run into problems with Enumerated types. To the database, I often store enum values as Strings, so the reverse engineering makes the field a String rather than an enum. My Entity bean has an enum annotated (@Enumerated(EnumType.STRING)).

                              • I rarely override the columnDefinition (for an enum code or iso code, for example). The reverse engineering translates char(n) columns to be varchar(n), then deployment fails because Hibernate does some validation.



                              All these things can be customized visually in the existing eclipse GUI for Hibernate Tools. Max is right now working frantically on getting seam-gen integrated into this GUI. So the above problems are really temporary issues.


                              • 12. Re: seam-gen enhancement
                                saeediqbal1

                                I am kind of confused. Does "everything" means this section "25.2. CRUD-application generator" from http://docs.jboss.com/seam/1.1.5.GA/reference/en/html/tools.html#d0e13161
                                ? I am just trying to follow the documentation and the tutorial movies you have on jboss wiki.

                                • 13. Re: seam-gen enhancement
                                  smokingapipe

                                  Speaking of SeamGen: I have one small bug fix for it: The Linux shell script should start with #!/bin/sh, not #/bin/sh. Without the #!, it doesn't execute poperly for tcsh users.

                                  • 14. Re: seam-gen enhancement
                                    gavin.king

                                     

                                    Does "everything" means this section "25.2. CRUD-application generator" from http://docs.jboss.com/seam/1.1.5.GA/reference/en/html/tools.html#d0e13161
                                    ? I am just trying to follow the documentation and the tutorial movies you have on jboss wiki.


                                    No wonder you're confused. The current rev of Hibernate Tools has nothing to do with the much more recent seam-gen, and generated code that does not work on recent releases of seam!

                                    Max is working on updating Hibernate Tools to integrate the most recent seam-gen but it is not done yet.

                                    1 2 Previous Next