Foros de discusión
Liferay EE 6.0.5 ServiceBuilder -- mapping relationship of a custom entity
J J G, modificado hace 13 años.
Liferay EE 6.0.5 ServiceBuilder -- mapping relationship of a custom entity
New Member Mensajes: 16 Fecha de incorporación: 8/06/07 Mensajes recientes
I am using Liferay Portal EE 6.0.5 + MySQL
How to map one-to-many or many-to-one relationship between entities in service.xml ?
I am building a Portlet using the Liferay Plugins SDK.
I am need to map a foreign key relationship between database table LAYOUT(default created by Liferay) and a new table I want to create (P_VERSION)
P_VERSION table would be holding a column "plid" which would refer to "plid" column of LAYOUT table.
Following is my service.xml
Now when I run ant "build-service" target the build is successful and the appropriate classes gets generated without any error.
But having a look at docroot/WEB-INF/sql/tables.sql
following can be seen
And in docroot/WEB-INF/service/com/sample/page/service/persistence/PVersionUtil.java I can see the generated method
com.sample.page.service.persistence.PVersionUtil.getLayouts(long)
I have the following queries:
a) I cannot find a setterXXX for associating an existing com.liferay.portal.Layout with my custom entity com.sample.page.PVersion.
I suppose there should be some configuration that should be added to the com.liferay.portal.Layout for making my mapping work.
But com.liferay.portal.Layout is an existing entity configured in <LIFERAY_PORTAL_ROOT>/portal-impl/src/com/liferay/portal/service.xml.
And it is available in my class-path so I cannot modify it.
So how to achieve the above mentioned configuration, in case my assumption is correct? If my assumption is wrong, then please guide me with the correct approach for achieving my desired requirement as mentioned above.
b) I cannot see any column named "plid" in CREATE STATEMENT in tables.sql shown above.Any specific reason in not including a foreign key constraint in the create clause? If it is not appended in the CREATE clause then how this constraint gets applied?
Thanks,
Jignesh
How to map one-to-many or many-to-one relationship between entities in service.xml ?
I am building a Portlet using the Liferay Plugins SDK.
I am need to map a foreign key relationship between database table LAYOUT(default created by Liferay) and a new table I want to create (P_VERSION)
P_VERSION table would be holding a column "plid" which would refer to "plid" column of LAYOUT table.
Following is my service.xml
<!--?xml version="1.0" encoding="UTF-8"?-->
<service-builder package-path="com.sample.page">
<namespace>SampleNS</namespace>
<entity name="PVersion" uuid="true" local-service="true" remote-service="true">
<!-- PK fields -->
<column name="id" type="long" primary="true" />
<!-- Group instance -->
<column name="groupId" type="long" />
<!-- Audit fields -->
<column name="companyId" type="long" />
<column name="userId" type="long" />
<column name="createDate" type="Date" />
<column name="modifiedDate" type="Date" />
<!-- Other fields -->
<column name="sampleId" type="long" />
<column name="version" type="double" />
<!-- Relationships -->
<column name="plid" type="Collection" entity="com.liferay.portal.Layout" mapping-key="plid" />
<!-- Order -->
<order>
<order-column name="sampleId" order-by="asc" />
<order-column name="version" order-by="desc" />
</order>
<!-- Finder methods -->
.....
....
<!-- References -->
....
....
</entity>
</service-builder>
Now when I run ant "build-service" target the build is successful and the appropriate classes gets generated without any error.
But having a look at docroot/WEB-INF/sql/tables.sql
following can be seen
create table SampleNS_PVersion (
uuid_ VARCHAR(75) null,
id_ LONG not null primary key,
groupId LONG,
companyId LONG,
userId LONG,
createDate DATE null,
modifiedDate DATE null,
sampleId LONG,
version DOUBLE
);
And in docroot/WEB-INF/service/com/sample/page/service/persistence/PVersionUtil.java I can see the generated method
com.sample.page.service.persistence.PVersionUtil.getLayouts(long)
I have the following queries:
a) I cannot find a setterXXX for associating an existing com.liferay.portal.Layout with my custom entity com.sample.page.PVersion.
I suppose there should be some configuration that should be added to the com.liferay.portal.Layout for making my mapping work.
But com.liferay.portal.Layout is an existing entity configured in <LIFERAY_PORTAL_ROOT>/portal-impl/src/com/liferay/portal/service.xml.
And it is available in my class-path so I cannot modify it.
So how to achieve the above mentioned configuration, in case my assumption is correct? If my assumption is wrong, then please guide me with the correct approach for achieving my desired requirement as mentioned above.
b) I cannot see any column named "plid" in CREATE STATEMENT in tables.sql shown above.Any specific reason in not including a foreign key constraint in the create clause? If it is not appended in the CREATE clause then how this constraint gets applied?
Thanks,
Jignesh
Tom Vleminckx, modificado hace 12 años.
RE: Liferay EE 6.0.5 ServiceBuilder -- mapping relationship of a custom ent
Junior Member Mensajes: 39 Fecha de incorporación: 27/06/11 Mensajes recientes
I'm having the same problem, already found a solution to this ?
chandrasekhar k, modificado hace 12 años.
RE: Liferay EE 6.0.5 ServiceBuilder -- mapping relationship of a custom ent
Regular Member Mensajes: 149 Fecha de incorporación: 7/07/09 Mensajes recientes
Hi,
I am also facing the same issue. Can any one suggest me the solution for it.
Thanks in advance.
Regards,
Chandrasekhar
I am also facing the same issue. Can any one suggest me the solution for it.
Thanks in advance.
Regards,
Chandrasekhar