3 Replies Latest reply on Oct 26, 2007 12:36 PM by taccart

    removing table prefix for generate-entities ?

    taccart

      Hi all

      I'm using seam since a few days (CR2), and first of all, a big thank you to all developpers involved :)

      My question is on reverse engenering side : I'm working on already existing tables.
      In the db, all tables are prefixed with a string

      TP_XS_*
      "driving generate-entities to create entities and pages names like
      tPXS*
      .

      Does any who knows how to define (I guess it's in hibernate) that tables are prefixed with a specific string that must be removed in generate-entities step ?


      Thanks for your answers



        • 1. Re: removing table prefix for generate-entities ?
          luizruiz

          You can use a custom ReverseEngineeringStrategy, overriding the tableToClassName or columnToPropertyName methods. Your class can extends org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy.

          • 2. Re: removing table prefix for generate-entities ?
            taccart


            Tell me if I'm on wrong tracks, I guess this must be set in the reveng used by seam ( jbossseamhome/seam-gen/hibernatetools/seam-gen.reveng.xml )

            I've found in hibernate doc that "It is possible to implement a user strategy" (http://www.hibernate.org/hib_docs/tools/reference/en/html/reverseengineering.html#custom-reveng-strategy)
            but it's not that much explicit

            anyway, thanks for the extra fast answer :)

            • 3. Re: removing table prefix for generate-entities ?
              taccart

              Okay, here's the solution:

              1/ create your class:

              import org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy;
              import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
              import org.hibernate.cfg.reveng.TableIdentifier;
              
              
              public class ExampleStrategy extends DelegatingReverseEngineeringStrategy {
              
               public ExampleStrategy (ReverseEngineeringStrategy delegate) {
               super(delegate);
               }
              
              @Override
              public String tableToClassName(TableIdentifier ti) {
               // TODO Auto-generated method stub
               if (ti.getName().startsWith("TP_XS_",0))
               { return ti.getName().substring(7).toLowerCase();
               }
               else
               return super.tableToClassName(ti); //
              }
              
              }
              

              2/ build the corresponding ExampleStrategy.jar

              3/ copy your jar to your /seam-gen/lib

              4/ Update the seam-gen/build.xml for target generate-entities:
              Add attribute reversestrategy to jdbcconfiguration :
              <jdbcconfiguration propertyfile="build.properties"
               reversestrategy="ExampleStrategy"
               packagename="${model.package}"
               revengfile="${project.home}/resources/seam-gen.reveng.xml"
               detectmanytomany="false"/>
              


              Read more info on hibernate ant tools : http://www.hibernate.org/hib_docs/tools/reference/en/html/ant.html