Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Aswin Giridhar
Liferay Service Builder
16 marzo 2012 12.43
Risposta

Aswin Giridhar

Punteggio: New Member

Messaggi: 15

Data di Iscrizione: 9 febbraio 2011

Messaggi recenti

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
16 marzo 2012 12.53
Risposta

David H Nebinger

Community Moderator

Punteggio: Liferay Legend

Messaggi: 11060

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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
16 marzo 2012 13.07
Risposta

Aswin Giridhar

Punteggio: New Member

Messaggi: 15

Data di Iscrizione: 9 febbraio 2011

Messaggi recenti

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
16 marzo 2012 13.14
Risposta

David H Nebinger

Community Moderator

Punteggio: Liferay Legend

Messaggi: 11060

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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
16 marzo 2012 13.15
Risposta

Joaquin Cabal

Punteggio: Junior Member

Messaggi: 54

Data di Iscrizione: 7 settembre 2009

Messaggi recenti

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
16 marzo 2012 13.18
Risposta

David H Nebinger

Community Moderator

Punteggio: Liferay Legend

Messaggi: 11060

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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
16 marzo 2012 13.28
Risposta

David H Nebinger

Community Moderator

Punteggio: Liferay Legend

Messaggi: 11060

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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
16 marzo 2012 13.38
Risposta

Joaquin Cabal

Punteggio: Junior Member

Messaggi: 54

Data di Iscrizione: 7 settembre 2009

Messaggi recenti

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
16 marzo 2012 13.40
Risposta

Aswin Giridhar

Punteggio: New Member

Messaggi: 15

Data di Iscrizione: 9 febbraio 2011

Messaggi recenti

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
16 marzo 2012 13.47
Risposta

Joaquin Cabal

Punteggio: Junior Member

Messaggi: 54

Data di Iscrizione: 7 settembre 2009

Messaggi recenti

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
16 marzo 2012 14.45
Risposta

Aswin Giridhar

Punteggio: New Member

Messaggi: 15

Data di Iscrizione: 9 febbraio 2011

Messaggi recenti

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
18 marzo 2012 16.54
Risposta

Joaquin Cabal

Punteggio: Junior Member

Messaggi: 54

Data di Iscrizione: 7 settembre 2009

Messaggi recenti

Exactly! when you add some Country for the region, you get the Liferay Country id, with CountryLocalServiceUtil
sheela mk
RE: Liferay Service Builder
25 aprile 2012 3.41
Risposta

sheela mk

Punteggio: Regular Member

Messaggi: 111

Data di Iscrizione: 16 febbraio 2012

Messaggi recenti

Oh My God..Got Solution!!!

emoticon