【问题标题】:Avoid generating header comments with Hibernate generation tools避免使用 Hibernate 生成工具生成标题注释
【发布时间】:2013-04-23 05:55:00
【问题描述】:

在生成DTO对象时,hibernate工具在header中生成cmets:

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

每代 cmets 都会更改(因为它们包含生成日期/时间)。

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

有没有办法避免生成上述标题?

谢谢。

【问题讨论】:

    标签: eclipse hibernate hibernate-tools


    【解决方案1】:

    您必须自定义 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>
    

    【讨论】:

    • 你的意思是我需要重新编译hibernate插件?我没有办法设置参数吗?
    • 我找到了 Pojo.ftl 文件,我将在Hibernate Code Generation Configurations 编辑器中将模板目录属性设置为我的模板目录,并通知您。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-05
    • 1970-01-01
    • 2011-10-08
    • 2016-10-15
    • 1970-01-01
    • 2015-11-18
    相关资源
    最近更新 更多