Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Ashwani Kumar
how to defining relationship in service.xml !!!
January 15, 2013 11:32 PM
Answer

Ashwani Kumar

Rank: Junior Member

Posts: 26

Join Date: October 19, 2012

Recent Posts

Hi All,

I want to create one-to-many relation betwen "teacher" and "course" entites..ie. One teacher can teach multiple courses.. so i created the below service.xml
<namespace>student</namespace>
<entity name="teacher" local-service="true" >
<column name="tID" type="long" primary="true" />
<column name="name" type="String" />
<column
name="courseList"
type="Collection"
entity="course"
mapping-key="tID" />
</entity>
<entity name="course" local-service="true" >
<column name="courseID" type="long" primary="true" />
<column name="name" type="String" />
<column name="tID" type="long" />
</entity>


after running ant build-service it is not creating getCourseList() function for teacher object...Is my service.xml is valid??

Thanks in advance..

-
Ashwani
Priyanka Dhingra
RE: how to defining relationship in service.xml !!!
January 16, 2013 12:21 AM
Answer

Priyanka Dhingra

Rank: Liferay Master

Posts: 501

Join Date: December 19, 2011

Recent Posts

hi
please check with
1teacherPersistence.getcourses(pk);
Ashwani Kumar
RE: how to defining relationship in service.xml !!!
January 16, 2013 1:33 AM
Answer

Ashwani Kumar

Rank: Junior Member

Posts: 26

Join Date: October 19, 2012

Recent Posts

Hi Priyanka,

Thanks for your quick reply...but as per the doument..on liferay.com.. It teacher class object should be injected to Course Class.

and the method like getTeacher() should be availble in Course class object..

But it is not working in this manner...


-
Ashwani..
Nicolas Tamayo
RE: how to defining relationship in service.xml !!!
January 16, 2013 6:27 AM
Answer

Nicolas Tamayo

Rank: Junior Member

Posts: 29

Join Date: October 3, 2012

Recent Posts

Hi Ashwani Kumar.

you must do this modification to your service.xml Document.

 1
 2<namespace>student</namespace>
 3<entity name="teacher" local-service="true" >
 4<column name="tID" type="long" primary="true" />
 5<column name="name" type="String" />
 6<column
 7name="courseList"
 8type="Collection"
 9entity="course"
10mapping-key="tID" />
11</entity>
12<entity name="course" local-service="true" >
13<column name="courseID" type="long" primary="true" />
14<column name="name" type="String" />
15<column name="tID" type="long" />
16
17<!-- The Addition -->
18<finder name="TeacherID" return-type="teacher">
19<finder-column name="tID"/>
20</finder>
21
22</entity>


with this addition in your service.xml Document when you generate the services, in your courseLocalServiceImpl. you will do a method that call the couserPersistence.findByTeacherID(long tID); in order of return the Teacher for this course.

I hope it helps you.
Priyanka Dhingra
RE: how to defining relationship in service.xml !!!
January 17, 2013 12:26 AM
Answer

Priyanka Dhingra

Rank: Liferay Master

Posts: 501

Join Date: December 19, 2011

Recent Posts

go through this link