Today we will discuss Many To Many relationship in Liferay
As discuss earlier Liferay Service Builder create tables with service.xml. But is there any way to provide Many To Many relationship between entities. Yes there is today we will discuss Many To Many relationship in liferay. Before Reading this blog it is highly recommended to read my previous blog on Service Builder in Detail.
Lets Start this step by step:-
Step 1:-Create service.xml
You can create service as mention in my previous article Service Builder in Detail .
service.xml
Just focus on line no 11 and 17:-
Explanation:-
Here we create a third entity(table) Employee_department Which contain the primary key of both tables.
Step 2:-Check point
Now build the service.xml and open tables.sql inside sql folder.
tables.sql
As you can see 3 tables are created two for entities and one for mapping.
Step 3:-Calling Services
Just create a doView() method and add data to the tables here we consider a scenario where one employee belong to two department.
Thats it just see the tables in database:-
You can Download source code from Many To Many mapping in Liferay
Hope this will help....
Related Post:-
Liferay Service Builder in Detail
Finder Method for Service Builder in Liferay
Custom Sql in Liferay
Custom Sql with two table in Liferay
Liferay Service Builder in Detail
How to install Maven
Creating Portlet/Services using Maven