Foros de discusión

services.xml one-to-many relation ship Problem

thumbnail
Florian Huber, modificado hace 13 años.

services.xml one-to-many relation ship Problem

Junior Member Mensajes: 29 Fecha de incorporación: 23/03/11 Mensajes recientes
Hello Board!

I try to create a Portlet which manages different Versions from various Applications! So i need an Database+Model like this:

 +-------------+               +---------+
 | Application |---------------| Version |
 +-------------+ 1    has    n +---------+


This shouldn be too tricky I thought and so i created a new Portlet Project and then a new services.xml

services.xml:
<!--?xml version="1.0" encoding="UTF-8"?-->

<service-builder package-path="myApplicationPortlet.service">
	<author>huwa</author>
	<namespace>appPortlet</namespace>
		<entity name="Application" local-service="true" remote-service="false">
		
        <!-- PK fields -->

        <column name="applicationId" 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="userName" type="String" />
        <column name="createDate" type="Date" />
        <column name="modifiedDate" type="Date" />

        <!-- Other fields -->

        <column name="name" type="String" /> <!-- Ubuntu -->
        <column name="versions" type="Collection" entity="Version" mapping-key="versionId" />

	</entity>
	<entity name="Version" local-service="true" remote-service="true">
		<column name="versionId" type="long" primary="true" />
		<column name="applicationId" type="long" />
		<column name="codeName" type="String" /><!-- 10.04 Lucid Lynx -->
	</entity>
	
</service-builder>


So, if I build the services, it translates it whitout errors, but

the generated Application Class haven't .getVersions() or .addVersion() ... Methods! The Version Class has the applicationId Column treaten as normal attribute.

Has anybody an idea for this strange behaviour?

Greetings
Florian
thumbnail
Florian Huber, modificado hace 13 años.

RE: services.xml one-to-many relation ship Problem

Junior Member Mensajes: 29 Fecha de incorporación: 23/03/11 Mensajes recientes
Today I also tried it with this service.xml


The build runs whitout Errors but it also don't create Object references :-/

Here the entity Plan:
   <entity name="Plan" remote-service="true" local-service="true" persistence-class="com.ext.portlet.plans.service.persistence.PlanPersistenceImpl">

                <!-- PK field -->
                <column name="planId" type="Long" primary="true" />

                <!-- Main fields -->

                <column name="name" type="String" />
                <column name="content" type="String" />
                <column name="shortcontent" type="String" />

                <!-- References to other entities -->
                
                <column name="planTypeId" type="Long" />

                <!-- Id of company -->
                <column name="companyId" type="Long" />
                <!-- Id of "parent" group, that is a group owning the portlet -->
                <column name="groupId" type="Long" />
                <!-- Id of group representing community working on a plan -->
                <column name="childGroupId" type="Long" />
                <!-- Id of forum category that holds discussion about a plan -->
                <column name="MBCategoryId" type="Long" />
                <!-- Id of referenced scenario -->
                <column name="scenarioId" type="String" />
                <!-- Id of debates topic related to plan -->
                <column name="topicId" type="String" />


                <column name="votes" type="Integer" />

                <!-- Important dates -->
                <column name="createDate" type="Date" />
                <column name="publishDate" type="Date" />

                <!-- Audit fields -->
                <column name="userId" type="Long" />
                <column name="userName" type="String" />
                <column name="userScreenName" type="String" />
                <column name="modifiedDate" type="Date" />
       

                <!-- Relationship -->
                <column name="planAttributes" type="Collection" entity="PlanAttribute" mapping-key="planId" />

                <!-- Order columns -->

                <order by="asc">
                        <order-column name="name" case-sensitive="false" />
                </order>

                <finder name="name" return-type="Collection">
                        <finder-column name="name" />
                </finder>

        </entity>


It creates this PlanModelImpl.java: http://pastebin.com/YL30FK2A

Anyone an idea how to solve this problem?
Sébastien Meunier, modificado hace 13 años.

RE: services.xml one-to-many relation ship Problem

Junior Member Mensajes: 33 Fecha de incorporación: 26/01/10 Mensajes recientes
Hello,

The methods to get Version from an Application / PlanAttributes from a Plan isn't in the Application / Plan classes but in the ApplicationPersistence / PlanPersistence classes (Accessible by using the variable applicationPersistence / planPersistence in your service).
thumbnail
Florian Huber, modificado hace 13 años.

RE: services.xml one-to-many relation ship Problem

Junior Member Mensajes: 29 Fecha de incorporación: 23/03/11 Mensajes recientes
Jeah, thank you!

But how do I get POJO's, where i can simply add/remove Objects? Like hibernate??
Aleksandar Vasilev, modificado hace 12 años.

RE: services.xml one-to-many relation ship Problem

New Member Mensajes: 13 Fecha de incorporación: 28/03/11 Mensajes recientes
Hi Florian,

Did you manage to fix it?

I have the same problem.

Please write me if you have fix.

regards,
Aleksandar
thumbnail
Florian Huber, modificado hace 12 años.

RE: services.xml one-to-many relation ship Problem

Junior Member Mensajes: 29 Fecha de incorporación: 23/03/11 Mensajes recientes
Hi,
no I have this problem also at this time, but I haven't done Liferay Development for the last couple of weeks, because we were on an exhibition.

But the next days I must find a way to solve this problem, because we need this for the next release! So if anyone has an solution or an hint, please leave a short notice!

greetings Florian

Edit: @Aleksandar: I will post the solution if I find it out myself! Can you also post it please if you find it?
thumbnail
devi nimmagadda, modificado hace 12 años.

RE: services.xml one-to-many relation ship Problem

Regular Member Mensajes: 109 Fecha de incorporación: 9/12/10 Mensajes recientes
Hi,

I am sending my service.xml please follow this procedure, u will not get any errors. I hope it helps to u

I have 3 tables PersonalEntry , EmployeeEntry , EducationEntry .... I am maintaining one-to-many relationship among 3 tables.

employeeId == primary key in PersonalEntry
employeeId == foreign key in EmployeeEntry
employeeId == foreign key in EducationEntry



<entity name="PersonalEntry" uuid="true" local-service="true" remote-service="true"
persistence-class="com.portlet.internalPortlet.service.persistence.PersonalEntryPersistenceImpl">


<column name="employeeId" type="int" primary="true"
id-type="class"
id-param="com.liferay.counter.service.persistence.IDGenerator"
/>
<column name="employeeEntries"
type="Collection"
entity="EmployeeEntry"
mapping-key="employeeId"/>

<column name="educationEntries"
type="Collection"
entity="EducationEntry"
mapping-key="employeeId"/>

<column name="deptId" type="int" />

<!-- Personal Details -->

<!-- Audit fields -->
<column name="userId" type="int" />
<column name="teamLeadId" type="int" />
<column name="lastName" type="String" />
<column name="firstName" type="String" />
<column name="middileName" type="String" />
<column name="nationality" type="String" />
<column name="dateOfBirth" type="Date" />
<column name="emailID" type="String" />
<column name="personalEmail" type="String" />
<column name="maritalStatus" type="String" />
<column name="gender" type="String" />
<column name="country" type="String" />
<column name="city" type="String" />
<column name="state" type="String" />
<column name="zipCode" type="long" />
<column name="mobile" type="long" />
<column name="emContactName" type="String" />
<column name="emRelationship" type="String" />
<column name="emtelephoneno" type="long" />
<column name="licenseNo" type="String" />
<column name="panNo" type="String" />
<column name="passportNo" type="String" />

<column name="imageName" type="String" />
<column name="documentName" type="String" />
<column name="copyResume" type="String" />

<column name="gid" type="int" />
<column name="createId" type="int" />
<column name="createUser" type="String" />
<column name="modifyId" type="int" />
<column name="modifiedUser" type="String" />


<column name="createDate" type="Date" />
<column name="modifiedDate" type="Date" />
<column name="status" type="boolean" />

<!-- Other fields -->

<!-- Order -->
<order by="asc">
<order-column name="firstName" case-sensitive="false" />

</order>
<!-- finder methods -->

<finder name="firstName" return-type="Collection">
<finder-column name="firstName"/>
</finder>


<finder name="userId" return-type="Collection">
<finder-column name="userId"/>
</finder>

<finder name="dateOfBirth" return-type="Collection">
<finder-column name="dateOfBirth"/>
</finder>

<finder name="deptId" return-type="Collection">
<finder-column name="deptId"/>
</finder>

<finder name="deptName" return-type="Collection">
<finder-column name="deptId"/>
</finder>
<finder name="emailID" return-type="Collection">
<finder-column name="emailID"/>
</finder>
</entity>

<!-- Employee Details Entry -->

<entity name="EmployeeEntry" uuid="true" local-service="true" remote-service="true"
persistence-class="com.portlet.internalPortlet.service.persistence.EmployeeEntryPersistenceImpl">


<column name="employeeEntryID" type="int" primary="true"
id-type="class"
id-param="com.liferay.counter.service.persistence.IDGenerator"
/>


<column name="employeeId" type="int" />


<!-- Audit fields -->
<column name="prevCompanyName" type="String" />
<column name="designation" type="String" />
<column name="startDate" type="Date" />
<column name="endDate" type="Date" />
<column name="salary" type="double" />

<column name="experience" type="int" />

<column name="expMonths" type="int" />
<column name="prevWorkEmail" type="String" />

<column name="createDate" type="Date" />
<column name="modifiedDate" type="Date" />
<column name="status" type="boolean" />


<!-- Order -->
<order by="asc">
<order-column name="salary" case-sensitive="false" />
</order>
<!-- finder methods -->

<finder name="designation" return-type="Collection">
<finder-column name="designation"/>
</finder>
<finder name="salary" return-type="Collection">
<finder-column name="salary"/>
</finder>
<finder name="employeeId" return-type="Collection">
<finder-column name="employeeId"/>
</finder>

</entity>

<!-- Education Details Entry -->

<entity name="EducationEntry" uuid="true" local-service="true" remote-service="true"
persistence-class="com.portlet.internalPortlet.service.persistence.EducationEntryPersistenceImpl">


<column name="educationId" type="int" primary="true"
id-type="class"
id-param="com.liferay.counter.service.persistence.IDGenerator"
/>
<column name="employeeId" type="int" />

<!-- Group instance -->


<!-- Audit fields -->
<column name="type" type="String" />
<column name="university" type="String" />
<column name="specialization" type="String" />
<column name="year" type="long" />
<column name="percentage" type="double" />

<column name="createDate" type="Date" />
<column name="modifiedDate" type="Date" />
<column name="status" type="boolean" />

<!-- Order -->
<order by="asc">
<order-column name="year" case-sensitive="false" />
</order>
<!-- finder methods -->

<finder name="university" return-type="Collection">
<finder-column name="university" />
</finder>
<finder name="employeeId" return-type="Collection">
<finder-column name="employeeId" />
</finder>
<finder name="EducationType" return-type="Collection">
<finder-column name="employeeId" />
<finder-column name="type" />
</finder>
<finder name="specialization" return-type="Collection">
<finder-column name="specialization" />
</finder>
</entity>
Aleksandar Vasilev, modificado hace 12 años.

RE: services.xml one-to-many relation ship Problem

New Member Mensajes: 13 Fecha de incorporación: 28/03/11 Mensajes recientes
Hi Devi,

I did it.

Thank you!

Have a nice day!
thumbnail
Florian Huber, modificado hace 12 años.

RE: services.xml one-to-many relation ship Problem

Junior Member Mensajes: 29 Fecha de incorporación: 23/03/11 Mensajes recientes
Hello,

i still get the same problem :/

can you please post your service.xml?

greetings florian
Aleksandar Vasilev, modificado hace 12 años.

RE: services.xml one-to-many relation ship Problem

New Member Mensajes: 13 Fecha de incorporación: 28/03/11 Mensajes recientes
Hello,

Unfortunately I cant send you my service.xml because I remove this connection.
You can get List of the connected objects by <entityname>Util class.

But the one in the previous post should be working and you could get list of EducationEntry with:

List<EducationEntry> educationEntries = PersonalEntryUtil.get....

I didn't compile it so it should be something like this.

I hope this help.

Regards,
Aleksandar