【发布时间】:2012-08-28 03:38:07
【问题描述】:
我正在尝试实现一个 FreeMarker 自定义逆向工程模板,该模板会自动创建我的 Hibernate 类。
在构建过程中,模板被 hibernate-tools 用来生成休眠类。
到目前为止,我为此目的使用了默认的 freemarker 模板,并且效果很好。
但现在我面临以下问题:
如何向默认的 getter-annotations 添加其他属性?
One-to-may 关联的默认 freemarker 方法是(在 Ejb3PropertyGetAnnotation.ftl 中实现):
...
<#elseif c2h.isCollection(property)>
${pojo.generateCollectionAnnotation(property, cfg)}
...
生成的java代码例如:
@OneToMany(fetch=FetchType.LAZY, mappedBy="person")
public Set<ContactInformation> getContactInformations() {
return this.contactInformations;
}
但我想像这样将 cascade = CascadeType.ALL 添加到每个一对多的 getter 注释中:
@OneToMany(cascade = CascadeType.ALL
fetch=FetchType.LAZY, mappedBy="person")
我是 freemarker 和 hibernate 的新手,不知道如何存档。
非常感谢您的帮助!
【问题讨论】:
标签: hibernate reverse-engineering freemarker hibernate-tools