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

发布于 2024-10-03 13:19:02 字数 3973 浏览 2 评论 0原文

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

I'm using hbm2java via maven to generate pojos, it will produce files such as Table.java, but what I want is AbstractTable.java

Is there an easy way to do this?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白云不回头 2024-10-10 13:19:02

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

custom templates do seem to be the way to go to achieve this.
In the end I extracted the pojo template files out of the jar so I could modify them and then used hbmtemplate on the pojo templates and filepattern to do this. It's a bit annoying that you can't just use the filepattern with hbm2pojo.

Here's my pom if anyone's interested:

            <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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文