Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Aswin Giridhar
Liferay Service Builder
March 16, 2012 12:43 PM
Answer

Aswin Giridhar

Rank: New Member

Posts: 15

Join Date: February 9, 2011

Recent Posts

Hey guys,

I am currently stuck in a problem where I have the following scenario:

I am creating a table called "Region", which has a relationship with the existing liferay table "Country". So the scenario is something like this, one region can have many countries.

In order to achieve this, I am creating a table regioncountry, which holds the foreign key of Region and Country table.

DB Schema:
Region: RegionId, Name
RegionCountry: RegionId, CountryId

How do i achieve this using Liferay Service builder ?

I have seen something similar in Liferay Portal service.xml (for relationship between Groups and Organization), but i I am not able to find any entity Groups_Orgs on the service.xml.

What is the best solution for this scenario ?
- Going for the above method
- Creating new column regionid on the existing liferay table Country
- Creating a new table altogether ?

Any help will be appreciated.

Thanks,
David H Nebinger
RE: Liferay Service Builder
March 16, 2012 12:53 PM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7250

Join Date: September 1, 2006

Recent Posts

If region contains multiple countries, then region would be an entity w/ a collection of countries, and country would be an entity w/ a region id.

You don't need the many to many relationship join table.
Aswin Giridhar
RE: Liferay Service Builder
March 16, 2012 1:07 PM
Answer

Aswin Giridhar

Rank: New Member

Posts: 15

Join Date: February 9, 2011

Recent Posts

David H Nebinger:
If region contains multiple countries, then region would be an entity w/ a collection of countries, and country would be an entity w/ a region id.

You don't need the many to many relationship join table.


Hi David,

Thanks for your reply.
So, that would mean overriding existing Liferay Country table to add the regionId there ?
I am just skeptical to change existing Liferay Entities, is that advisable to do ?
David H Nebinger
RE: Liferay Service Builder
March 16, 2012 1:14 PM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7250

Join Date: September 1, 2006

Recent Posts

Oh, the part about wanting to use the Liferay country entity was not apparent.

You're right about not wanting to modify the Liferay entities, it would make upgrades difficult.

So instead I'd do the Region entity that has a collection of "MyCountry" entities. The MyCountry entity would have the region id and the Liferay Country as an entity. That should give you what you're looking for, correct?
Joaquin Cabal
RE: Liferay Service Builder
March 16, 2012 1:15 PM
Answer

Joaquin Cabal

Rank: Junior Member

Posts: 49

Join Date: September 7, 2009

Recent Posts

Hi David,
Is ok the modeling, but what would be the way for create these services?
If I have to create a new service I would create it in a new portlet for example, but if a have a relationship with an existing Liferay model like "Country", How would be this? Could be in a Hook plugin or maybe an Ext plugin , overriding the portal service builder?
David H Nebinger
RE: Liferay Service Builder
March 16, 2012 1:18 PM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7250

Join Date: September 1, 2006

Recent Posts

No, you'd stick w/ your regular portlet w/ the service builder in there.

You will still have access to Liferay's CountryLocalServiceUtil (or whatever it is) for fetching countries, you'd just be setting the result into the MyCountry entity...
David H Nebinger
RE: Liferay Service Builder
March 16, 2012 1:28 PM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 7250

Join Date: September 1, 2006

Recent Posts

David H Nebinger:
No, you'd stick w/ your regular portlet w/ the service builder in there.

You will still have access to Liferay's CountryLocalServiceUtil (or whatever it is) for fetching countries, you'd just be setting the result into the MyCountry entity...


The more I think about this, I realize it's not going to work. The Country object you get back from Liferay is actually an interface to an instance from another class loader.

I guess I would make the MyCountry entity hold the region id and the country id. Get the list of MyCountry entities using the region, then you'd have to manually call the CountryLocalServiceUtil (or whatever it is) to pull back the country instance.

Adding it as an EXT plugin would get around this issue, but SB usage in EXT plugins is either deprecated now or will be in the future (I know I saw a note about that somewhere). Since a hook is in a different class loader, it would face the same issue as a regular portlet implementation...
Joaquin Cabal
RE: Liferay Service Builder
March 16, 2012 1:38 PM
Answer

Joaquin Cabal

Rank: Junior Member

Posts: 49

Join Date: September 7, 2009

Recent Posts

Thanks David, I have sent last post, viewing only your first post.
Is a good idea to have two entities for this case, and MyCountry entity having a relation to Liferay Country
Aswin Giridhar
RE: Liferay Service Builder
March 16, 2012 1:40 PM
Answer

Aswin Giridhar

Rank: New Member

Posts: 15

Join Date: February 9, 2011

Recent Posts

David H Nebinger:
Oh, the part about wanting to use the Liferay country entity was not apparent.

You're right about not wanting to modify the Liferay entities, it would make upgrades difficult.

So instead I'd do the Region entity that has a collection of "MyCountry" entities. The MyCountry entity would have the region id and the Liferay Country as an entity. That should give you what you're looking for, correct?



How do we do that ?
is this something like this ?
<entity name="myRegion" local-service="true" remote-service="true">

<column name="regionId" primary="true" type="long"></column>

<column name="name" type="String"></column>
<column name="defaultLanguage" type="long"></column>
<column name="countries" type="Collection" entity="MyCountry" mapping-key="regionId" />

</entity>
<entity name="myCountry" local-service="true" remote-service="true">

<column name="countryId" primary="true" type="long"></column>
<column name="regionId" type="long"></column>

<column name="countries" type="Collection" entity="Country" mapping-key="countryId" />
<reference entity="Country" package-path="com.liferay.portal"/>
</entity>
Joaquin Cabal
RE: Liferay Service Builder
March 16, 2012 1:47 PM
Answer

Joaquin Cabal

Rank: Junior Member

Posts: 49

Join Date: September 7, 2009

Recent Posts

Hi Aswin,

It would be like that

<entity name="myRegion" local-service="true" remote-service="true">
<column name="regionId" primary="true" type="long"></column>

<column name="name" type="String"></column>
<column name="defaultLanguage" type="long"></column>
<column name="countries" type="Collection" entity="MyCountry" mapping-key="regionId" />

</entity>
<entity name="myCountry" local-service="true" remote-service="true">

<column name="countryId" primary="true" type="long"></column>
<column name="regionId" type="long"></column>
</entity>

MyCountry is only for have a relation to Liferay Country
Aswin Giridhar
RE: Liferay Service Builder
March 16, 2012 2:45 PM
Answer

Aswin Giridhar

Rank: New Member

Posts: 15

Join Date: February 9, 2011

Recent Posts

Joaquin Cabal:
Hi Aswin,

It would be like that

<entity name="myRegion" local-service="true" remote-service="true">
<column name="regionId" primary="true" type="long"></column>

<column name="name" type="String"></column>
<column name="defaultLanguage" type="long"></column>
<column name="countries" type="Collection" entity="MyCountry" mapping-key="regionId" />

</entity>
<entity name="myCountry" local-service="true" remote-service="true">

<column name="countryId" primary="true" type="long"></column>
<column name="regionId" type="long"></column>
</entity>

MyCountry is only for have a relation to Liferay Country



So when we use mycountry, we create a custom finder and add methods on that mycountry service and then query the liferay country (CountryLocalServiceUtil) to populate myCountry right ?
Joaquin Cabal
RE: Liferay Service Builder
March 18, 2012 4:54 PM
Answer

Joaquin Cabal

Rank: Junior Member

Posts: 49

Join Date: September 7, 2009

Recent Posts

Exactly! when you add some Country for the region, you get the Liferay Country id, with CountryLocalServiceUtil
sheela mk
RE: Liferay Service Builder
April 25, 2012 3:41 AM
Answer

sheela mk

Rank: Regular Member

Posts: 111

Join Date: February 16, 2012

Recent Posts

Oh My God..Got Solution!!!

emoticon