What's the easiest way to amend the file name of pojos during hbm2java generation
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>
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>
精彩评论