RE: Service Builder Persistance Impl Errors in case of TableMapper

thumbnail
Aliasgar Kapadiya, modified 7 Years ago. New Member Posts: 16 Join Date: 10/31/16 Recent Posts
Greetings,

We are working on migration of service builder code from 6.2 to DXP/7.0 using IDE.

Now, in case of Liferay 6.2 we have used "mapping-table" feature for few entities. When trying to use similar entities in Liferay 7 IDE, we are getting errors in *PersistanceImpl of that entity.

Below is my build.gradle:-
dependencies {
	compileOnly group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "+"
	compileOnly group: "com.liferay", name: "com.liferay.osgi.util", version: "+"
	compileOnly group: "com.liferay", name: "com.liferay.portal.spring.extender", version: "+"
	compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "+"
	compileOnly project(":modules:sample-service:sample-service-api")
}

buildService {
	apiDir = "../sample-service-api/src/main/java"
}

group = "sample.service"


Below is my entity definition:-
<entity name="Employee" remote-service="false" local-service="true">
        <column name="employeeId" type="long" primary="true"></column>
        <column name="name" type="String"></column>
        <column name="deptId" type="Collection" entity="Department" mapping-table="Employee_department" />
    </entity>
    <entity name="Department" remote-service="false" local-service="true">
        <column name="deptId" type="long" primary="true"></column>
        <column name="name" type="String"></column>
        <column name="employeeId" type="Collection" entity="Employee" mapping-table="Employee_department" />
    </entity>


Below is the error in DepartmentPersistanceImpl (Similar case for EmployeePersistanceImpl):-
The method getCompanyId() is undefined for the type Department

Please find Attached screenshot of the same.

Appreciate your response in this matter.
Thanks and Regards,
Aliasgar Pratapgarhwala
thumbnail
Terry Jia, modified 7 Years ago. New Member Posts: 14 Join Date: 11/29/10 Recent Posts
hey Aliasgar,
can you try to add the column
<column name="companyId" type="long" />
into your both two entities?
thumbnail
Aliasgar Kapadiya, modified 7 Years ago. New Member Posts: 16 Join Date: 10/31/16 Recent Posts

Yes it works, Thank you for your response.

thumbnail
Andrew Jardine, modified 7 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts

Just to add some advice here, based on my own experience. 

 

When the Service Builder "template" service.xml file is generated there is a section with companyId, groupId, userId, userName, createDate, modifiedDate. I would recommend that you always leave those fields and complete them when creating records. You may not need them now, but they provide a certain degree of future proofing in the even that you need to reuse this same entity across multiple sites or portal instances -- it allows you to properly scope data for different properties in the same table. 

thumbnail
Jorge Díaz, modified 7 Years ago. Liferay Master Posts: 753 Join Date: 1/9/14 Recent Posts

Since 7.0 version, companyId column was added to all Liferay tables in order to allow configuring data partitioning at database level by instances (companyId).

 

So perhaps there is some servicebuilder code that takes for granted every entity has companyId field.