フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
R charan
Using Foreign Key in Service.xml
2009/11/27 3:55
答え

R charan

ランク: Junior Member

投稿: 72

参加年月日: 2008/10/28

最近の投稿

hi all,

i had developed portlets with ext-environment using service.xml successfully. Only thing missing was how to use foreign key feature in service.xml. iam using two tables and the second table field (such as item id ) must be related to item id of first table . How to relate both similar to foreign key. any help would be appreciable

thanks in advace ,
rc
Wilson Man
RE: Using Foreign Key in Service.xml
2009/11/27 15:44
答え

Wilson Man

LIFERAY STAFF

ランク: Liferay Master

投稿: 580

参加年月日: 2006/06/21

最近の投稿

service.xml doesn't check for foreign key restriction. you'll just have to create a column with key referencing the primary key of another table and name them the same way. Though you can alter your table to add the foreign key restriction in your database, though i haven't tried it myself and can't give you more info than what's given.
R charan
RE: Using Foreign Key in Service.xml
2009/11/29 20:49
答え

R charan

ランク: Junior Member

投稿: 72

参加年月日: 2008/10/28

最近の投稿

thanks for reply


you'll just have to create a column with key referencing the primary key of another table and name them the same way.


can you post a sample one
Kowbathullah Gnaniyar
RE: Using Foreign Key in Service.xml
2009/11/30 1:13
答え

Kowbathullah Gnaniyar

ランク: Liferay Master

投稿: 603

参加年月日: 2007/12/19

最近の投稿

Hi Charan,

You have to create 2 entity then give take any one of the field from first entity give as a Primary key for another entity.

 1
 2
 3<?xml version="1.0"?>
 4<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 5.2.3//EN" "http://www.liferay.com/dtd/liferay-service-builder_4_0_0.dtd">
 5
 6<service-builder root-dir=".." package-path="com.liferay.portlet">
 7    <portlet name="Testingone" short-name="Testingone" />
 8    <entity name="Testingone" local-service="true" remote-service="true">
 9
10        <!-- PK fields -->
11        <column name="testoneId" type="String" primary="true" />
12
13                 <!-- Other fields -->
14        <column name="testfield1" type="String" />
15        <column name="testfield2" type="String" />
16   
17
18
19    </entity>
20
21    <entity name="Testingtwo" local-service="true" remote-service="true">
22
23        <!-- PK fields -->
24        <column name="testfield1" type="String" primary="true" />
25
26            <!-- Other fields -->
27        <column name="testfield3" type="String" />
28        <column name="testfield4" type="String" />
29       
30       </entity>
31   
32        <exceptions>
33        <exception>Testingone</exception>
34        <exception>TestingTwo</exception>
35    </exceptions>
36</service-builder>


- Gnaniyar Zubair
R charan
RE: Using Foreign Key in Service.xml
2009/11/30 4:15
答え

R charan

ランク: Junior Member

投稿: 72

参加年月日: 2008/10/28

最近の投稿

hi, thanx for reply

but, according to service.xml,

The testfield1 indeed will be a primary field in entity 2 but how it is related to testfield1 of entity 1 (as a foreign key). It is no where mentioned. IT will be treated as two different columns, rather imposing a foreign key relation on testfield1 of entity 1 and testfield1 of entity 2.
Kowbathullah Gnaniyar
RE: Using Foreign Key in Service.xml
2009/11/30 4:29
答え

Kowbathullah Gnaniyar

ランク: Liferay Master

投稿: 603

参加年月日: 2007/12/19

最近の投稿

Hi charan,


we are not giving mapping in service.xml .

when you update the entity1 -> testfield1, the same time you have to update the entity2 -> testfield2 also in coding level.


- Gnaniyar Zubair .
R charan
RE: Using Foreign Key in Service.xml
2009/12/01 2:19
答え

R charan

ランク: Junior Member

投稿: 72

参加年月日: 2008/10/28

最近の投稿

This updatation is the normal procedure that we follow . we need to write the code to check the primary key value is first table exists or not and then we need to allow submission in second table. And also any value can be added from database, so again we need to apply foreign key constraint on the table.

Iam searching for this feature in service.xml,

when we specify any column of entity 2 (which is a primary key) with relation to entity one column (as foreign key), then the method which is created on the primary column of entity 2 (for ex: getUserId()) must check the values from entity 1 then only it must add

Vote here
Eduardo P García
RE: Using Foreign Key in Service.xml
2010/03/25 12:23
答え

Eduardo P García

ランク: New Member

投稿: 10

参加年月日: 2009/10/01

最近の投稿

Does the relationship established through mapping-table and mapping-key control the integrity? I mean, whenever rows in the master (referenced) table are deleted, the respective rows of the child (referencing) table with a matching mapping-key will get deleted as well (similar to cascade delete).

Thanks
chandru palaniyappan
RE: Using Foreign Key in Service.xml
2011/01/24 21:51
答え

chandru palaniyappan

ランク: Junior Member

投稿: 85

参加年月日: 2010/07/28

最近の投稿

Hi Gnaniyar Zubair,

Can you please provide a sample portlet for this...!


Thanks & Regards

Chandru P
who ever
RE: Using Foreign Key in Service.xml
2011/01/25 1:05
答え

who ever

ランク: New Member

投稿: 22

参加年月日: 2010/11/18

最近の投稿

Eduardo P García:
Does the relationship established through mapping-table and mapping-key control the integrity?


Since Liferay does not use foreign key constraints to ensure referential integrity yet, you have to delete all child rows manually. See http://issues.liferay.com/browse/LPS-13418