在liferay中生成one to many 关系说明

?

liferay中生成one to many 关系说明

1:在service.xml中配置

For example

<column< p="">

?????? name="shoppingItemPrices"

?????? type="Collection"

?????? entity="ShoppingItemPrice"

?????? mapping-key="itemId"

/>

说明: entitymapping-key属性被指定将建立一个一对多的关系。

2:运行ant build

?????? 生成相关文件

3:在生成的实体实现类中,如ShoppingItemImp.java,新增getShoppingItemPrice()方法

?????? For example

?????? public List getItemPrices()

?????? throws PortalException, SystemException {

/*此处return2种写法

第一种是要求在关系实体中定义根据关联实体id进行查询的方法,如:

*/

return ShoppingItemPriceLocalServiceUtil.getItemPrices(getItemId());

/*

第二种是通过业务层代理类获的实体的持久类实例进行操作

*/

return ActiveEntryLocalServiceUtil.getActiveEntryPersistence().getCheckItemEntries(this.getActiveId());

??? }

4:再次运行 ant build

如此便可在使用实体的时候直接获取关联对象实体

如:

List list = ActiveEntry.getCheckItemEntries ();

如果要在hbm配置文件中生成一对多关系描述,则需修改freemarker模板文件

文件路径:com/liferay/portal/tool/servicebuilder/dependencies/hbm_xml.flt

(如果对其他生成文件内容做调整,也可修改其他对应的模板文件)

修改为如下内容(也可直接copy

<#list entities as entity>

??? <#if entity.hasColumns()>

?????? <class name="${packagePath}.model.impl.${entity.name}Impl" table="${entity.table}">

?????????? <cache usage="read-write">

?????????? <#if entity.hasCompoundPK()>

????????????? <composite-id name="primaryKey" class="${packagePath}.service.persistence.${entity.name}PK">

????????????????? <#assign pkList = entity.getPKList()>

????????????????? <#list pkList as column>

???????????????????? <key-property name="${column.name}" <="" span="">

???????????????????? <#if column.name != column.DBName>

???????????????????????? column="${column.DBName}"

???????????????????? <!---->

???????????????????? />

????????????????? <!---->

????????????? </composite-id>

?????????? <#else>

????????????? <#assign column = entity.getPKList()?first>

????????????? <id name="${column.name}" <="" span="">

????????????? ??? <#if column.name != column.DBName>

???????????????????? column="${column.DBName}"

????????????????? <!---->

????????????????? type="<#if !entity.hasPrimitivePK()>java.lang.<!---->${column.type}">

????????????????? <#if column.idType??>

???????????????????? <#assign class = serviceBuilder.getGeneratorClass("${column.idType}")>

???????????????????? <#if class == "class">

???????????????????????? <#assign class = column.IdParam>

???????????????????? <!---->

????????????????? <#else>

???????????????????? <#assign class = "assigned">

????????????????? <!---->

????????????????? <generator class="${class}" <="" span="">

????????????????? <#if class == "sequence">

???????????????????????? ${column.IdParam}

???????????????????? </generator>

????????????????? <#else>

???????????????????? />

????????????????? <!---->

????????????? </id>

?????????? <!---->

?????????? <#list entity.columnList as column>

????????????? <#if column.EJBName??>

????????????????? <#assign ejbName = true>

????????????? <#else>

????????????????? <#assign ejbName = false>

????????????? <!---->

????????????? <#if !column.isPrimary() && !column.isCollection() && !ejbName>

????????????????? <property name="${column.name}" <="" span="">

????????????????? <#if column.name != column.DBName>

???????????????????? column="${column.DBName}"

????????????????? <!---->

????????????????? <#if column.isPrimitiveType() || column.type == "String">

????????????????? ??? type="com.liferay.util.dao.hibernate.${serviceBuilder.getPrimitiveObj("${column.type}")}Type"

????????????????? <!---->

????????????????? />

????????????? <!---->

????????????? <#if !column.isPrimary() && column.isCollection()>

????????????????? ????

????????????????? <#if column.isMappingOneToMany()>

???????????????? ????????

???????????????????????? <key column="${column.getMappingKey()}">

???????????????????????? <one-to-many class="${packagePath}.service.persistence.${column.EJBName}">

????????????????????????

?????? ?????????????<!---->

???????????????????

????????????? <!---->

?????????? <!---->

?????? </class>

??? <!---->

<!---->



礼物 2008-12-18 08:39 发表评论

你可能感兴趣的:(DAO,freemarker,Hibernate,xml,ant)