避免使用Hibernate生成工具生成标题注释

时间:2013-04-22 20:38:38

标签: eclipse hibernate hibernate-tools

生成DTO对象时,hibernate工具会在标题中生成注释:

// Generated 22 avr. 2013 20:29:27 by Hibernate Tools 3.4.0.CR1

每一代评论都会改变(因为它们包含生成日期/时间)。

问题是在我的SVN中我最终得到了许多无用的更改,因此我必须检查每个生成的文件以查看是否提交(如果它包含实际更改)或覆盖它(如果它只是标题)。

有没有办法避免生成所谓的标题?

谢谢。

1 个答案:

答案 0 :(得分:2)

您必须自定义hibernate-tools.jar中的Freemarker模板。导航至/pojo/Pojo.ftl并删除行// Generated ${date} by Hibernate Tools ${version}

检查这个可能会有所帮助:https://forum.hibernate.org/viewtopic.php?f=6&t=989777&view=next

Hibernate工具Ant任务的一个示例(通过指定templatepathhbmtemplate属性:

<hibernatetool destdir="hibernate-model-gen/pojo" templatepath="hibernate-model-gen/customized-templates">
    <jdbcconfiguration configurationfile="hibernate-model-gen/hibernate.cfg.xml" packagename="open.pub.proto.core.model" revengfile="hibernate-model-gen\gen-conf\hibernate.reveng.xml" detectmanytomany="true" />
    <hbmtemplate templateprefix="pojo/" template="pojo/Pojo.ftl" filepattern="{package-name}/{class-name}.java">
        <property key="jdk5" value="true" />
        <property key="ejb3" value="true" />
    </hbmtemplate>
</hibernatetool>