掲示板

Using Foreign Key in Service.xml

thumbnail
14年前 に R charan によって更新されました。

Using Foreign Key in Service.xml

Junior Member 投稿: 72 参加年月日: 08/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
thumbnail
14年前 に Wilson Man によって更新されました。

RE: Using Foreign Key in Service.xml

Liferay Master 投稿: 581 参加年月日: 06/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.
thumbnail
14年前 に R charan によって更新されました。

RE: Using Foreign Key in Service.xml

Junior Member 投稿: 72 参加年月日: 08/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
thumbnail
14年前 に Gnaniyar Zubair によって更新されました。

RE: Using Foreign Key in Service.xml

Liferay Master 投稿: 722 参加年月日: 07/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.



<!--?xml version="1.0"?-->


<service-builder root-dir=".." package-path="com.liferay.portlet">
	<portlet name="Testingone" short-name="Testingone" />
	<entity name="Testingone" local-service="true" remote-service="true">

		<!-- PK fields -->
		<column name="testoneId" type="String" primary="true" />

                 <!-- Other fields -->
		<column name="testfield1" type="String" />
		<column name="testfield2" type="String" />
	


	</entity>

	<entity name="Testingtwo" local-service="true" remote-service="true">

		<!-- PK fields -->
		<column name="testfield1" type="String" primary="true" />

	        <!-- Other fields -->
		<column name="testfield3" type="String" />
		<column name="testfield4" type="String" />
		
       </entity>
	
        <exceptions>
		<exception>Testingone</exception>
		<exception>TestingTwo</exception>
	</exceptions>
</service-builder>




- Gnaniyar Zubair
thumbnail
14年前 に R charan によって更新されました。

RE: Using Foreign Key in Service.xml

Junior Member 投稿: 72 参加年月日: 08/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.
thumbnail
14年前 に Gnaniyar Zubair によって更新されました。

RE: Using Foreign Key in Service.xml

Liferay Master 投稿: 722 参加年月日: 07/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 .
thumbnail
14年前 に R charan によって更新されました。

RE: Using Foreign Key in Service.xml

Junior Member 投稿: 72 参加年月日: 08/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
thumbnail
13年前 に chandru palaniyappan によって更新されました。

RE: Using Foreign Key in Service.xml

Junior Member 投稿: 85 参加年月日: 10/07/29 最新の投稿
Hi Gnaniyar Zubair,

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


Thanks & Regards

Chandru P
thumbnail
14年前 に Eduardo P Garcia によって更新されました。

RE: Using Foreign Key in Service.xml

New Member 投稿: 10 参加年月日: 09/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
13年前 に Jens Göring によって更新されました。

RE: Using Foreign Key in Service.xml

New Member 投稿: 22 参加年月日: 10/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