留言板

ServiceBuilder - Issue with one-to-many relationship

Duc Duc,修改在12 年前。

ServiceBuilder - Issue with one-to-many relationship

New Member 帖子: 3 加入日期: 11-11-1 最近的帖子
I got problem with ServiceBuilder

This is my service.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">

<service-builder package-path="stu.bookstore">
<author>Duc Anh</author>
<namespace>stu_bookstore</namespace>
<entity name="Catalog" local-service="true" remote-service="false">
<column name="catalogId" type="long" primary="true"></column>
<column name="catalogName" type="String"></column>

<column name="books" type="Collection" entity="Book" mapping-key="catalogId"></column>

</entity>

<entity name="Book" local-service="true" remote-service="false">
<column name="bookId" type="long" primary="true"></column>
<column name="title" type="String"></column>
<column name="price" type="double"></column>
<column name="quantity" type="int"></column>

<column name="catalogId" type="long"></column>

</entity>
</service-builder>

But I cannot find any results by defining this line: <column name="books" type="Collection" entity="Book" mapping-key="catalogId"></column>

There are no setters or getters or attributes in the Catalog-Classes or at least errors or warnings. The line is completely ignored.

What are we doing wrong?
thumbnail
Hitesh Methani,修改在12 年前。

RE: ServiceBuilder - Issue with one-to-many relationship

Regular Member 帖子: 171 加入日期: 10-6-24 最近的帖子
+1, same issue even I am facing.

Regards,
Hitesh Methani
Peter Hellstrand,修改在12 年前。

RE: ServiceBuilder - Issue with one-to-many relationship

Regular Member 帖子: 166 加入日期: 11-11-30 最近的帖子
Did any of you solve this? I am having the same problem.
Mohamed Rizwanuzaman,修改在12 年前。

RE: ServiceBuilder - Issue with one-to-many relationship

New Member 帖子: 20 加入日期: 09-12-17 最近的帖子
Hi Duc,

I have same problem while dealing with one to many relationship in service builder. Its solved for me.
I had the followed the below steps in LR-6.1
After you mentioned the mapping-key in service builder ,do ant-build-service,
It will a generate a method in persistence class of your entity related to your mapping-key.
Using the persistence method you can write the getters method in your implementation class and do ant build service before deploying it.
In your case:
you have to write a method to get the list of book associate with catalog id. Correct me if i wrong

Here is my example in localserviceimpl class for my scenario. it will list out the all employees associate to the department.

public class DepartmentLocalServiceImpl extends DepartmentLocalServiceBaseImpl {

public List<Employee> getDepartmentEmployees(long departmentId) throws SystemException, Exception {
List<Employee> employeeList = departmentPersistence.getEmployees(departmentId);

return employeeList;
}
}


now then you can access the util class in your action file.

Example to get list of employees related to department.

List<Employee> employeeList = DepartmentLocalServiceUtil.getDepartmentEmployees(departmentId);

Hope this step will give you some idea.
you can find my service builder in attachements
Regards,
Rizwan