- In Real life Student can assign to multiple course. Here we see example of One to Many where student can assign to many courses.
Create service in portlet.
- Add below content in your portlet service.
<entity name="Student" local-service="true" remote-service="true" cache-enabled="false">
<column name="studentId" type="long" primary="true" />
<column name="courses" type="Collection" entity="Course"/>
</entity>
<entity name="Course" local-service="true" remote-service="true" cache-enabled="false">
<column name="courseId" type="long" primary="true" />
<column name="studentId" type="long"/>
<finder name="courseId" return-type="Collection">
<finder-column name="courseId" />
</finder>
<finder name="studentId" return-type="Collection">
<finder-column name="studentId" />
</finder>
</entity>
- Run service.
- Now add below method in CourseLocalServiceImpl to make to finder mehod in publicly available with help of CourseLocalServiceUtil.
public List<Course> getCourseForStudent(Long studentId) throws SystemException{
return this.coursePersistence.findBystudentId(studentId);
}
- Now Again run Service.
- The method will available in CourseLocalServiceUtil which can use anywhere in your portlet.
Comments
Post a Comment