在hbm2java生成期间修改pojos文件名的最简单方法是什么

时间:2010-11-19 15:19:58

标签: hibernate maven-2 reverse-engineering hbm2java

我通过maven使用hbm2java来生成pojos,它会生成Table.java等文件,但我想要的是AbstractTable.java

有一种简单的方法吗?

从我的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>

1 个答案:

答案 0 :(得分:2)

自定义模板似乎是实现这一目标的方法。 最后,我从jar中提取了pojo模板文件,以便我可以修改它们,然后在pojo模板和filepattern上使用hbmtemplate来执行此操作。你不能只使用带有hbm2pojo的文件模式,这有点令人讨厌。

如果有人感兴趣,这是我的pom:

            <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>