2010-11-19 59 views
2

我使用調用:hbm2java通過Maven來生成的POJO,它會產生的文件,如Table.java,但我要的是AbstractTable.java什麼是修改調用:hbm2java生成過程中的POJO的文件名,最簡單的方法

是否有捷徑可尋?

從我的pom.xml:

 <plugin> 
<groupId>org.codehaus.mojo</groupId> 
<artifactId>hibernate3-maven-plugin</artifactId> 
<version>2.2</version> 
<executions> 
    <execution> 
     <id>hbm2hbmxml</id> 
     <phase>generate-sources</phase> 
     <goals> 
      <goal>hbm2hbmxml</goal> 
     </goals> 
     <configuration> 
      <components> 
       <component> 
        <name>hbm2hbmxml</name> 
        <outputDirectory>src/main</outputDirectory> 
       </component> 
      </components> 
    <componentProperties> 
    <revengfile>src/conf/reveng.xml</revengfile> 
    <propertyfile>src/conf/hibernate.properties</propertyfile> 
    <templatepath>src/conf/hibernate-templates</templatepath> 
    <jdk5>true</jdk5> 
    </componentProperties> 
     </configuration> 
    </execution> 
    <execution> 
     <id>hbm2cfgxml</id> 
     <phase>generate-sources</phase> 
     <goals> 
      <goal>hbm2cfgxml</goal> 
     </goals> 
     <configuration> 
      <components> 
       <component> 
        <name>hbm2cfgxml</name> 
        <outputDirectory>src/main</outputDirectory> 
       </component> 
      </components> 
    <componentProperties> 
    <revengfile>src/conf/reveng.xml</revengfile> 
    <propertyfile>src/conf/hibernate.properties</propertyfile> 
    <templatepath>src/conf/hibernate-templates</templatepath> 
    <jdk5>true</jdk5> 
    </componentProperties> 
     </configuration> 
    </execution> 
    <execution> 
     <id>hbm2java</id> 
     <phase>generate-sources</phase> 
     <goals> 
      <goal>hbm2java</goal> 
     </goals> 
     <configuration> 
      <components> 
       <component> 
        <name>hbm2java</name> 
        <outputDirectory>src/main</outputDirectory> 
       </component> 
      </components> 
    <componentProperties> 
    <revengfile>src/conf/reveng.xml</revengfile> 
    <propertyfile>src/conf/hibernate.properties</propertyfile> 
    <templatepath>src/conf/hibernate-templates</templatepath> 
    <jdk5>true</jdk5> 
    <namingstrategy>uk.co.company.product.hibernate.CustomNamingStrategy</namingstrategy> 
    </componentProperties> 
     </configuration> 
    </execution> 
</executions> 
<dependencies> 
<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-tools</artifactId> 
    <version>3.2.3.GA</version> 
</dependency> 
<dependency> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>hibernate3-maven-plugin</artifactId> 
    <version>2.2</version> 
</dependency> 
      <dependency> 
       <groupId>mysql</groupId> 
       <artifactId>mysql-connector-java</artifactId> 
       <version>5.0.8</version> 
      </dependency> 
      <dependency> 
       <groupId>cglib</groupId> 
       <artifactId>cglib-nodep</artifactId> 
       <version>2.1_3</version> 
      </dependency> 
</dependencies> 
    </plugin> 

回答

2

自定義模板似乎是去實現這一目標的方式。 最後,我將pojo模板文件從jar中提取出來,以便我可以修改它們,然後在pojo模板和filepattern上使用hbmtemplate來執行此操作。有點煩人,你不能只用hbm2pojo來使用文件模式。

這裏是我的聚甲醛如果任何人的興趣:

  <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>hibernate3-maven-plugin</artifactId> 
      <version>2.2</version> 
      <executions> 
       <execution> 
        <id>hbm2hbmxml</id> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>hbm2hbmxml</goal> 
        </goals> 
        <configuration> 
         <components> 
          <component> 
           <name>hbm2hbmxml</name> 
           <outputDirectory>src/main</outputDirectory> 
          </component> 
         </components> 
         <componentProperties> 
          <revengfile>src/conf/reveng.xml</revengfile> 
          <propertyfile>src/conf/hibernate.properties</propertyfile> 
          <templatepath>src/conf/hibernate-templates</templatepath> 
          <jdk5>true</jdk5> 
         </componentProperties> 
        </configuration> 
       </execution> 
       <execution> 
        <id>hbm2cfgxml</id> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>hbm2cfgxml</goal> 
        </goals> 
        <configuration> 
         <components> 
          <component> 
           <name>hbm2cfgxml</name> 
           <outputDirectory>src/main</outputDirectory> 
          </component> 
         </components> 
         <componentProperties> 
          <revengfile>src/conf/reveng.xml</revengfile> 
          <propertyfile>src/conf/hibernate.properties</propertyfile> 
          <templatepath>src/conf/hibernate-templates</templatepath> 
          <jdk5>true</jdk5> 
         </componentProperties> 
        </configuration> 
       </execution> 
       <execution> 
        <id>hbmtemplate0</id> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>hbmtemplate</goal> 
        </goals> 
        <configuration> 
         <components> 
          <component> 
           <name>hbmtemplate</name> 
           <outputDirectory>src/main</outputDirectory> 
          </component> 
         </components> 
         <componentProperties> 
          <revengfile>src/conf/reveng.xml</revengfile> 
          <propertyfile>src/conf/hibernate.properties</propertyfile> 
          <templatepath>src/conf/hibernate-templates</templatepath> 
          <jdk5>true</jdk5> 
          <ejb3>false</ejb3> 
          <filepattern>{package-name}/Abstract{class-name}.java</filepattern> 
          <templateprefix>pojo/</templateprefix> 
          <destdir>src/main</destdir> 
          <template>pojo/Pojo.ftl</template> 
         </componentProperties> 
        </configuration> 
       </execution> 
       <execution> 
        <id>hbmtemplate1</id> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>hbmtemplate</goal> 
        </goals> 
        <configuration> 
         <components> 
          <component> 
           <name>hbmtemplate</name> 
           <outputDirectory>src/main</outputDirectory> 
          </component> 
         </components> 
         <componentProperties> 
          <revengfile>src/conf/reveng.xml</revengfile> 
          <propertyfile>src/conf/hibernate.properties</propertyfile> 
          <templatepath>src/conf/hibernate-templates</templatepath> 
          <jdk5>true</jdk5> 
          <ejb3>false</ejb3> 
          <filepattern>{package-name}/{class-name}.java</filepattern> 
          <templateprefix>pojoImpl/</templateprefix> 
          <destdir>src/main</destdir> 
          <template>pojoImpl/PojoImpl.ftl</template> 
         </componentProperties> 
        </configuration> 
       </execution> 
       <execution> 
        <id>hbmtemplate2</id> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>hbmtemplate</goal> 
        </goals> 
        <configuration> 
         <components> 
          <component> 
           <name>hbmtemplate</name> 
           <outputDirectory>src/main</outputDirectory> 
          </component> 
         </components> 
         <componentProperties> 
          <revengfile>src/conf/reveng.xml</revengfile> 
          <propertyfile>src/conf/hibernate.properties</propertyfile> 
          <templatepath>src/conf/hibernate-templates</templatepath> 
          <jdk5>true</jdk5> 
          <ejb3>false</ejb3> 
          <filepattern>{package-name}/Abstract{class-name}DAO.java</filepattern> 
          <templateprefix>dao/</templateprefix> 
          <destdir>src/main</destdir> 
          <template>dao/daohome.ftl</template> 
          <sessionFactoryName>sessionFactoryName.goes.here</sessionFactoryName> 
         </componentProperties> 
        </configuration> 
       </execution> 
       <execution> 
        <id>hbmtemplate3</id> 
        <phase>generate-sources</phase> 
        <goals> 
         <goal>hbmtemplate</goal> 
        </goals> 
        <configuration> 
         <components> 
          <component> 
           <name>hbmtemplate</name> 
           <outputDirectory>src/main</outputDirectory> 
          </component> 
         </components> 
         <componentProperties> 
          <revengfile>src/conf/reveng.xml</revengfile> 
          <propertyfile>src/conf/hibernate.properties</propertyfile> 
          <templatepath>src/conf/hibernate-templates</templatepath> 
          <jdk5>true</jdk5> 
          <ejb3>false</ejb3> 
          <filepattern>{package-name}/{class-name}DAO.java</filepattern> 
          <templateprefix>daoImpl/</templateprefix> 
          <destdir>src/main</destdir> 
          <template>daoImpl/daoImpl.ftl</template> 
          <sessionFactoryName>sessionFactoryName.goes.here</sessionFactoryName> 
         </componentProperties> 
        </configuration> 
       </execution> 
      </executions> 
      <dependencies> 
       <dependency> 
        <groupId>org.hibernate</groupId> 
        <artifactId>hibernate-tools</artifactId> 
        <version>3.2.3.GA</version> 
       </dependency> 
       <dependency> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>hibernate3-maven-plugin</artifactId> 
        <version>2.2</version> 
       </dependency> 
       <dependency> 
        <groupId>mysql</groupId> 
        <artifactId>mysql-connector-java</artifactId> 
        <version>5.0.8</version> 
       </dependency> 
       <dependency> 
        <groupId>cglib</groupId> 
        <artifactId>cglib-nodep</artifactId> 
        <version>2.1_3</version> 
       </dependency> 
      </dependencies> 
     </plugin> 
相關問題