【问题标题】:What's the easiest way to amend the file name of pojos during hbm2java generationhbm2java生成期间修改pojos文件名的最简单方法是什么
【发布时间】:2011-05-12 16:49:01
【问题描述】:

我是通过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>

【问题讨论】:

    标签: hibernate maven-2 reverse-engineering hbm2java


    【解决方案1】:

    自定义模板似乎确实是实现这一目标的方法。 最后,我从 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-06
      • 2012-12-09
      • 2010-09-23
      • 1970-01-01
      • 2016-10-18
      • 2014-01-29
      • 1970-01-01
      相关资源
      最近更新 更多