我使用hibernate的当前设置使用hibernate.reveng.xml文件生成各种hbm.xml文件。然后使用hbm2java将其转换为POJO。我们在设计模式时花了一些时间,在表和列中放置了一些相当不错的描述。当使用hbm.xml生成这些描述时,我能够将它们拖到hbm2jhbmxml文件中。
所以我得到了类似的东西:
<class name="test.Person" table="PERSONS">
<comment>The comment about the PERSONS table.</comment>
<property name="firstName" type="string">
<column name="FIRST_NAME" length="100" not-null="true">
<comment>The first name of this person.</comment>
</column>
</property>
<property name="middleInitial" type="string">
<column name="MIDDLE_INITIAL" length="1">
<comment>The middle initial of this person.</comment>
</column>
</property>
<property name="lastName" type="string">
<column name="LAST_NAME" length="100">
<comment>The last name of this person.</comment>
</column>
</property>
</class>那么,我如何告诉hbm2java 将这些注释拉出并放入创建的文件中呢?
我在这上读过关于编辑共济会模板以改变代码生成方式的文章。我理解这个概念,但它并不是要详细说明除了前后条件的例子之外,您还可以做些什么。
发布于 2010-04-01 13:33:28
在生成的POJO中添加javadoc的通常方法是使用meta标记,如下所示:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<class name="Person">
<meta attribute="class-description">
Javadoc for the Person class
@author Frodo
</meta>
<id name="id" type="long">
<meta attribute="scope-set">protected</meta>
<generator class="increment"/>
</id>
<property name="name" type="string">
<meta attribute="field-description">The name of the person</meta>
</property>
</class> 因此,为了获得类似的内容,但包括表和列的注释,我对POJO中的Javadoc注释线程的理解是,您必须修改用于生成hbm文件的模板。
要做到这一点,请查看hibernate-tools.jar,hbm/persistentclass.hbm.ftl、hbm/property.hbm.ftl等的共济会模板(这不是一个详尽的列表)并对它们进行修改。
例如,在hbm/persistentclass.hbm.ftl中,而不是:
<#if clazz.table.comment?exists && clazz.table.comment?trim?length!=0>
<comment>${clazz.table.comment}</comment>
</#if>我想你可以:
<#if clazz.table.comment?exists && clazz.table.comment?trim?length!=0>
<meta attribute="class-description">
${clazz.table.comment}
</meta>
<comment>${clazz.table.comment}</comment>
</#if>诸若此类。
https://stackoverflow.com/questions/2539237
复制相似问题