Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Duc Duc
ServiceBuilder - Issue with one-to-many relationship
December 12, 2011 1:38 AM
Answer

Duc Duc

Rank: New Member

Posts: 3

Join Date: October 31, 2011

Recent Posts

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?
Hitesh Methani
RE: ServiceBuilder - Issue with one-to-many relationship
December 12, 2011 1:47 AM
Answer

Hitesh Methani

Rank: Regular Member

Posts: 114

Join Date: June 24, 2010

Recent Posts

+1, same issue even I am facing.

Regards,
Hitesh Methani
Peter Hellstrand
RE: ServiceBuilder - Issue with one-to-many relationship
March 17, 2012 10:07 AM
Answer

Peter Hellstrand

Rank: Regular Member

Posts: 167

Join Date: November 30, 2011

Recent Posts

Did any of you solve this? I am having the same problem.
Mohamed Rizwanuzaman
RE: ServiceBuilder - Issue with one-to-many relationship
March 27, 2012 2:57 AM
Answer

Mohamed Rizwanuzaman

Rank: New Member

Posts: 17

Join Date: December 16, 2009

Recent Posts

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
Attachments: service.xml (1.1k)