在随笔中发了一篇XDoclet Template In Eclipse的内容,在实际使用过程中,我又按照个人习惯,进行了分类编辑,以便于更快捷的使用。
<?xml version="1.0" encoding="UTF-8"?>
<templates><template name="@hib-blob-byte" description="blob to byte" context="javadoc" enabled="true" deleted="false" autoinsert="true">@hibernate.property column="${enclosing_method}" type="org.springframework.orm.hibernate3.support.BlobByteArrayType" lazy="true" </template><template name="@hib-class" description="@hibernate.class" context="javadoc" enabled="true" deleted="false" autoinsert="true">@hibernate.class table="${enclosing_type}" dynamic-update="true"</template><template name="@hib-class-disc" description="@hibernate.discriminator" context="javadoc" enabled="true" deleted="false" autoinsert="true">@hibernate.discriminator column="type" type="character" not-null="true" force="false"</template><template name="@hib-class-join" description="hibernate join subclass" context="javadoc" enabled="true" deleted="false" autoinsert="true">@hibernate.joined-subclass table="${primary_type_name}" lazy="true" dynamic-update="true"
*@hibernate.joined-subclass-key column="${primary_type_name}Guid" * *请修改子类的表名,对应表的主键,该主键不需要定义在类的属性中,它对应父类的主键
</template><template name="@hib-class-sub" description="@hibernate.subclass" context="javadoc" enabled="true" deleted="false" autoinsert="true">@hibernate.subclass name="${file}" discriminator-value=""</template><template name="@hib-id-assign" description="id is assign" context="javadoc" enabled="true" deleted="false" autoinsert="true">@hibernate.id generator-class="assigned" length="20" column="请修改" </template><template name="@hib-id-guid" description="id is guid" context="javadoc" enabled="true" deleted="false" autoinsert="true">@hibernate.id generator-class="uuid" type="java.lang.String"
* @hibernate.column name="guid" sql-type="VARCHAR(38)" not-null="true" *
* 请修改name of column的值</template><template name="@hib-rel-many-to-many-list" description="many to many list" context="javadoc" enabled="true" deleted="false" autoinsert="true">@hibernate.list name="方法名(无Get)" inverse="true" cascade="save-update"
* lazy="true"
* @hibernate.collection-key column="外键"
* @hibernate.collection-index column="tabIndex" type="int"
* @hibernate.collection-one-to-many class="关联的类"
*
* 请修改外键,并且指定完整的关联类的类名(包+类名)</template><template name="@hib-rel-many-to-many-set" description="many 2 many set" context="javadoc" enabled="true" deleted="false" autoinsert="true">@hibernate.set name="${enclosing_method}" table="关联表" cascade="save-update" inverse="true" lazy="true" * @hibernate.collection-key column="自己的主键" * @hibernate.collection-many-to-many class="关联类" column="关联类的主键" * * 两个类的主键构成关联表的属性,关联类请写完整的类名 * 多对多时,只能指定一个多的方向断子为true,即inverse="true" * 多对多时,无法指定index顺序,因为你无法确定从两个方向看上去都具有顺序,所以使用List不可靠 </template><template name="@hib-rel-many-to-one" description="@hibernate.many-to-one" context="javadoc" enabled="true" deleted="false" autoinsert="true">@hibernate.many-to-one column="${enclosing_method}_ID" class="${return_type}" cascade="none" outer-join="auto" not-null="false" lazy="true"
* * 请给class指定完整的包名+类名
* @return ${return_type}
*</template><template name="@hib-rel-one-to-many-list" description="@hibernate.one-to-many relationship" context="javadoc" enabled="true" deleted="false" autoinsert="true">@hibernate.list name="${enclosing_method}" inverse="true" cascade="save-update" lazy="true" * @hibernate.collection-key column="外键" * @hibernate.collection-index column="TABINDEX" type="int" * @hibernate.collection-one-to-many class="关联的类" * * 请修改外键,并且指定完整的关联类的类名(包+类名) </template><template name="@hib-rel-one-to-many-set" description="one 2 many set" context="javadoc" enabled="true" deleted="false" autoinsert="true">@hibernate.set name="${enclosing_method}" inverse="true" cascade="save-update" lazy="true"
* @hibernate.collection-key column="外键"
* @hibernate.collection-one-to-many class="关联的类"
*
* 请修改外键,并且指定完整的关联类的类名(包+类名)
</template><template name="@hib-rel-parent-child-list" description="one to mang [construct a tree]" context="javadoc" enabled="true" deleted="false" autoinsert="true">@hibernate.list lazy="true" inverse="true" cascade="all"
* @hibernate.collection-key column="parentGuid"
* @hibernate.collection-index column="tabIndex"
* @hibernate.collection-one-to-many class="${enclosing_package}.${primary_type_name}"
*
* 请修改collection-key,它是many方的外键
* tabIndex可以修改,也可以不修改,而且类中不必要一定有这个属性存在,因为它是Hib在操作List时需要的一个属性,只需数据库中定义了即可。
</template><template name="@hib-string-clob" description="hibernate string to clob" context="javadoc" enabled="true" deleted="false" autoinsert="true">@hibernate.property name="${enclosing_method}" column="ORG_Description" type="org.springframework.orm.hibernate3.support.ClobStringType" not-null="false" unique="false" length="4000" </template></templates>
如何倒入参考随笔。
代码实例:
/**
* @hibernate.id generator-class="uuid" type="java.lang.String"
* name="guid" column="A_GUID" length="38"
*
*/
public java.lang.String getGuid() {
return orgGuid;
}
private Set childDepartment;
/**
* @hibernate.set lazy="false" cascade="all" lazy="true"
* @hibernate.collection-key column="Superior_GUID"
* @hibernate.collection-one-to-many class="model.Department"
*
* @return Set
*/
public Set getChildDepartment() {
return childDepartment;
}
public void setChildDepartment(Set childDepartment) {
this.childDepartment = childDepartment;
}
private Set roles;
/**
* many to may
*
* @hibernate.set name="roles" table="ORG_DEPT_REF_ROLE"
* cascade="save-update" inverse="true" lazy="true"
* @hibernate.collection-key column="DEPT_GUID"
* @hibernate.collection-many-to-many class="model.Role"
* column="ROLE_GUID"
* @return Set
*/
public Set getRoles() {
return roles;
}
public void setRoles(Set roles) {
this.roles = roles;
}
private List positions;
/**
*
* @hibernate.list name="positions" inverse="true" cascade="save-update"
* lazy="true"
* @hibernate.collection-key column="DEPT_GUID"
* @hibernate.collection-index column="POSITION_TABINDEX" type="int"
* @hibernate.collection-one-to-many class="model.Position"
*
* 请修改外键,并且指定完整的关联类的类名(包+类名)
*/
public List getPositions() {
return positions;
}
public void setPositions(List positions) {
this.positions = positions;
}