在liferay中生成one to many 关系说明
来源:互联网 发布:内存优化 编辑:程序博客网 时间:2024/05/21 10:46
在liferay中生成one to many 关系说明
1:在service.xml中配置
For example:
<column
name="shoppingItemPrices"
type="Collection"
entity="ShoppingItemPrice"
mapping-key="itemId"
/>
说明: entity和mapping-key属性被指定将建立一个一对多的关系。
2:运行ant build
生成相关文件
3:在生成的实体实现类中,如ShoppingItemImp.java,新增getShoppingItemPrice()方法
For example:
public List getItemPrices()
throws PortalException, SystemException {
/*此处return有2种写法
第一种是要求在关系实体中定义根据关联实体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}"
<#if column.name != column.DBName>
column="${column.DBName}"
</#if>
/>
</#list>
</composite-id>
<#else>
<#assign column = entity.getPKList()?first>
<id name="${column.name}"
<#if column.name != column.DBName>
column="${column.DBName}"
</#if>
type="<#if !entity.hasPrimitivePK()>java.lang.</#if>${column.type}">
<#if column.idType??>
<#assign class = serviceBuilder.getGeneratorClass("${column.idType}")>
<#if class == "class">
<#assign class = column.IdParam>
</#if>
<#else>
<#assign class = "assigned">
</#if>
<generator class="${class}"
<#if class == "sequence">
<param name="sequence">${column.IdParam}</param>
</generator>
<#else>
/>
</#if>
</id>
</#if>
<#list entity.columnList as column>
<#if column.EJBName??>
<#assign ejbName = true>
<#else>
<#assign ejbName = false>
</#if>
<#if !column.isPrimary() && !column.isCollection() && !ejbName>
<property name="${column.name}"
<#if column.name != column.DBName>
column="${column.DBName}"
</#if>
<#if column.isPrimitiveType() || column.type == "String">
type="com.liferay.util.dao.hibernate.${serviceBuilder.getPrimitiveObj("${column.type}")}Type"
</#if>
/>
</#if>
<#if !column.isPrimary() && column.isCollection()>
<#if column.isMappingOneToMany()>
<set name="${column.name}" lazy="true">
<key column="${column.getMappingKey()}"/>
<one-to-many class="${packagePath}.service.persistence.${column.EJBName}" />
</set>
</#if>
</#if>
</#list>
</class>
</#if>
</#list>
- 在liferay中生成one to many 关系说明
- NHibernate中many-to-one映射关系
- Grails2中One-to-many关系
- 用我的MyGeneration模板生成NHibernate映射文件和关系(one-to-one,one-to-many,many-to-many)
- 用MyGeneration模板生成NHibernate映射文件和关系(one-to-one,one-to-many,many-to-many)
- 我的MyGeneration模板生成NHibernate映射文件和关系(one-to-one,one-to-many,many-to-many)
- 解决问题(十)——HashCodeBuilder在one-to-many关系中出现Lazy异常
- cascade属性通常在one-to-many关系里应用
- Hibernate中many-to-one关系的编写
- Hibernate中many-to-one关系的编写
- Hibernate中many-to-one关系的编写
- hibernate syn使用中 one-to-many 说明
- Hibernate one-to-many / many-to-one关系映射
- Hibernate one-to-many / many-to-one关系映射
- Hibernate one-to-many && many-to-many 的关系映射
- Entity Framework 实体关系总结:one-to-one, one-to-many, many-to-many
- Entity Framework 实体关系总结:one-to-one, one-to-many, many-to-many
- 码农小汪-Hibernate学习4-关联关系映射many-to-one,many-to-one,one-to-many
- eclipse 反应慢 优化
- 本体开发方法——the Method of Ontology Development
- JDK的命令详解(1)
- java面试基础
- 常用js验证(2)
- 在liferay中生成one to many 关系说明
- 蚂蚁是如何更新信息素的?如何根据概率进行选择的?(编程实现)
- 关于自动开关机的一些经验
- Servelt入门
- XSL中实现输入一个日期返回此日期的星期
- jena 学习思路(转)
- 关于NTFS压缩被禁用
- 《建筑桩基技术规范》JGJ94-2008
- ServerVariables