google.com, pub-5747754088801811, DIRECT, f08c47fec0942fa0 Skip to main content

One to Many Relationship liferay


  • 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

Popular posts from this blog

Disable cache content of browser access on back button after logout liferay dxp

Some time we have requirement where we do not want to allow back button after logout and show cached browser content. Liferay provide properties which with we are able to restrict to see content on back button after logout. If user click back button after logout it will show the login page. We require to provide below properties in portal-ext.properties. Restart the server once applying below properties browser.cache.signed.in.disabled=true

Model Listener Hook

                             Liferay Hook provide facility to create listener on particular model. We require to implement implements ModelListener on our custom class. Lets create one Hook which allow to do action on the various activity on particular model action. Create one hook.(e.g. UserListener-hook) Add portal properties inside liferay-hook.xml file under web inf.  <?xml version="1.0"?> <!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd"> <hook> <portal-properties>portal.properties</portal-properties> </hook>  It will create portal.properties inside src folder.  Add below property inside portlet.properties file             value.object.listener.com.liferay.portal.model.User=com.sa.CreateAccountHook In above property we have created listener for the Us...