Sunday 13 September 2015

one to Many Implementation in Liferay

Liferay providing mapping-key attribute for column from this we can achieve one to many relation between entities (tables)

The entities which are participated in one to many relations, for those entities(tables) we have to define column and that column should have mapping-key attribute and entity attributes.

Service.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
<service-builder package-path="com.test.training">
<author>Veera Reddy</author>
<namespace>ommp</namespace>
<entity name="TableOne" local-service="true" remote-service="false">
   <column name="tableOneId" type="long" primary="true" />
        <column name="tableTwoId" type="long"></column>
        <column name="tableTwoReference" type="Collection" entity="TableTwo" mapping-key="tableTwoId" />
</entity>
 <entity name="TableTwo" local-service="true" remote-service="false">
  <column name="tableTwoId" type="long" primary="true" />
</entity>
</service-builder>
 Run the service builder you will get generated following sql tables.
create table ommp_TableOne (
tableOneId LONG not null primary key,
tableTwoId LONG
);

create table ommp_TableTwo (
tableTwoId LONG not null primary key
);

No comments:

Post a Comment