您可以更新原始的 freemarker 模板以适应您的要求。我们是这样做的:
1) 在我们表的 reveng 条目中添加一个“allocation-size-50”元属性:
<table name="Checklisteneintrag" >
<meta attribute="allocation-size-50"/>
<primary-key>
<generator class="sequence">
<param name="sequence_name">Checklisteneintrag_Seq</param>
</generator>
</primary-key>
</table>
2) 获取原始的“Ejb3PropertyGetAnnotation.ftl”并对其进行调整以从以下代码开始:
<#if ejb3>
<#if pojo.hasIdentifierProperty()>
<#if property.equals(clazz.identifierProperty)>
<#if pojo.hasMetaAttribute("allocation-size-50")>
${pojo.generateAnnIdGenerator()?replace('@SequenceGenerator(', '@SequenceGenerator(allocationSize=50, initialValue=1, ')}
</#if>
<#if !pojo.hasMetaAttribute("allocation-size-50")>
${pojo.generateAnnIdGenerator()?replace('@SequenceGenerator(', '@SequenceGenerator(allocationSize=1, initialValue=1, ')}
</#if>
</#if>
</#if>
....
3) 将所有 ftl 文件(原始文件和改编的文件)放入可以通过逆向工程找到的目录中,例如在 maven 中,我们引用 templatepath="src/hibernate/resources/templates" 如下:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution> <!-- set MAVEN_OPTS="-Dfile.encoding=UTF-8" && mvn antrun:run@hbm2java -->
<id>hbm2java</id>
<phase>none</phase>
<configuration>
<target>
<echo message="Start generating entities .." />
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" />
<hibernatetool templatepath="src/hibernate/resources/templates">
<classpath>
<path location="${project.build.directory}/classes" />
<path location="${project.basedir}/src/hibernate/resources" />
</classpath>
<!-- Note that configurationfile does not work anymore in Hibernate
5.4.0 -->
<jdbcconfiguration propertyfile="src/hibernate/resources/hibernate.properties" revengfile="src/hibernate/resources/hibernate.reveng.xml" reversestrategy="at.rsg.lp.flow.hibernate.FlowRevEngStrategy" packagename="at.rsg.lp.flow.services.jpa.model" detectmanytomany="true" />
<!-- jdbcconfiguration configurationfile="src/hibernate/resources/hibernate.cfg.xml"
revengfile="src/hibernate/resources/hibernate.reveng.xml" reversestrategy="at.rsg.lp.flow.hibernate.FlowRevEngStrategy"
packagename="at.rsg.lp.flow.services.impl.jpa" detectmanytomany="true"
/ -->
<hbm2java destdir="src/main/java" jdk5="true" ejb3="true" />
</hibernatetool>
<echo message="End generating entities" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>