Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
saleem khan
How to create one to many relationship in Liferay 6.2
June 6, 2014 2:54 AM
Answer

saleem khan

Rank: Junior Member

Posts: 42

Join Date: November 15, 2013

Recent Posts

Hi.....
I am new to liferay,
Can any tell how to create one to many relation ship in liferay 6.2
i thought of using mapping-key but as the mapping key is removed, i dont no how to create a one to many relationship.
have tried the following code added in service.xml but Methods and related to that code are not getting generated.

<!-- Relationship -->
<column name="lmsBorrowings" type="Collection" entity="LMSBorrowing" />

can any pleas suggest the solution
thansk. emoticon
Meera Prince
RE: How to create one to many relationship in Liferay 6.2
June 6, 2014 3:06 AM
Answer

Meera Prince

Rank: Liferay Master

Posts: 814

Join Date: February 8, 2011

Recent Posts

Hi
Have a look into following link it may help you..

http://www.liferaysavvy.com/2014/01/liferay-service-builder-many-to-many_12.html


Regards,
Meera Prince
saleem khan
RE: How to create one to many relationship in Liferay 6.2
June 6, 2014 3:20 AM
Answer

saleem khan

Rank: Junior Member

Posts: 42

Join Date: November 15, 2013

Recent Posts

I need how to create one to many relationship pleas tell how to do it liferay 6.2
saleem khan
RE: How to create one to many relationship in Liferay 6.2
June 6, 2014 3:59 AM
Answer

saleem khan

Rank: Junior Member

Posts: 42

Join Date: November 15, 2013

Recent Posts

Have tried above method of yours in the website but getting an exception pleas tell me whats wrong below is the code of service.xml

 1<?xml version="1.0" encoding="UTF-8"?>
 2<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_2_0.dtd">
 3<service-builder package-path="com.slayer">
 4    <author>saleem</author>
 5    <namespace>LMS</namespace>
 6
 7    <entity name="LMSBook" local-service="true" remote-service="false">
 8        <!-- PK fields -->
 9        <column name="bookId" type="long" primary="true" id-type="increment"/>
10       
11        <!-- UI fields -->
12        <column name="bookTitle" type="String" />
13        <column name="author" type="String" />
14       
15        <!-- Relationship -->
16        <column name="lmsBorrowings" type="Collection"
17                entity="LMSBorrowing" mapping-table="bookId"/>
18                        
19        <!-- Here by default mapping-key is the primary key
20             so no need of using mapping-key attribute and also support for
21             mapping-key attribute has been removed in liferay6.2 see DTD for more details-->
22       
23        <!-- Audit fields -->
24        <column name="dateAdded" type="Date" />
25        <column name="modifiedDate" type="Date"/>
26       
27        <order by="desc">
28            <order-column name="modifiedDate"></order-column>
29        </order>
30       
31        <finder return-type="Collection" name="BookTitle">
32            <finder-column name="bookTitle"/>
33        </finder>
34       
35        <finder return-type="LMSBook" name="BookTitle_Author">
36            <finder-column name="bookTitle"/>
37            <finder-column name="author"/>
38        </finder>
39       
40        <reference package-path="com.liferay.portal" entity="Image"/>
41    </entity>
42   
43   
44    <entity name="LMSBorrowing" local-service="true"
45            remote-service="false">
46            <!-- PK fields -->
47            <column name="borrowingId" type="long" primary="true" id-type="increment"/>
48            
49            <!-- FK fields -->
50            <column name="bookId" type="long"/>
51            <column name="memberId" type="long"/>
52            
53            <!-- Audit fields -->
54            <column name="dateBorrowed" type="Date"/>
55            <column name="dateReturned" type="Date"/>
56            
57            <finder return-type="Collection" name="BookId">
58                <finder-column name="bookId"></finder-column>
59            </finder>
60            
61    </entity>
62</service-builder>


and getting the following exception while building the service layer.

  1[Console output redirected to file:E:\Liferay\LIFERAY\.metadata\.plugins\com.liferay.ide.sdk.core\sdk.log]
  2Buildfile: E:\Liferay\LIFERAY\liferay-plugins-sdk-6.2\portlets\library-portlet\build.xml
  3build-service:
  4      [jar] Building MANIFEST-only jar: E:\Liferay\LIFERAY\liferay-plugins-sdk-6.2\portlets\library-portlet\build-service-classpath.jar
  5   [delete] Deleting: E:\Liferay\LIFERAY\liferay-plugins-sdk-6.2\portlets\library-portlet\build-service-classpath.jar.manifest
  6   [delete] Deleting: E:\Liferay\LIFERAY\liferay-plugins-sdk-6.2\portlets\library-portlet\build-service-classpath.jar
  7     [echo] Loading jar:file:/E:/Liferay/LIFERAY/liferay-portal-6.2-ce-ga2/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/system.properties
  8     [echo] Loading jar:file:/E:/Liferay/LIFERAY/liferay-portal-6.2-ce-ga2/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties
  9     [echo] Loading jar:file:/E:/Liferay/LIFERAY/liferay-portal-6.2-ce-ga2/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/com/liferay/portal/tools/dependencies/portal-tools.properties
 10     [echo] Building LMSBook
 11     [echo] Writing E:\Liferay\LIFERAY\liferay-plugins-sdk-6.2\portlets\library-portlet\docroot\WEB-INF\src\com\slayer\service\persistence\LMSBookPersistenceImpl.java
 12     [echo] Writing E:\Liferay\LIFERAY\liferay-plugins-sdk-6.2\portlets\library-portlet\docroot\WEB-INF\service\com\slayer\service\persistence\LMSBookPersistence.java
 13     [echo] Writing E:\Liferay\LIFERAY\liferay-plugins-sdk-6.2\portlets\library-portlet\docroot\WEB-INF\service\com\slayer\service\persistence\LMSBookUtil.java
 14     [echo] 10:43:09,300 ERROR [main][runtime:96] Template processing error: "Method public java.util.List com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(java.lang.String) throws java.io.IOException threw an exception when invoked on com.liferay.portal.tools.servicebuilder.ServiceBuilder@4d4a3cb9"
 15     [echo] Method public java.util.List com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(java.lang.String) throws java.io.IOException threw an exception when invoked on com.liferay.portal.tools.servicebuilder.ServiceBuilder@4d4a3cb9
 16     [echo] The problematic instruction:
 17     [echo] ----------
 18     [echo] ==> list serviceBuilder.getMappingEntities(column.mappingTable) as mapColumn [on line 280, column 41 in com/liferay/portal/tools/servicebuilder/dependencies/model_impl.ftl]
 19     [echo] ----------
 20     [echo] Java backtrace for programmers:
 21     [echo] ----------
 22     [echo] freemarker.template.TemplateModelException: Method public java.util.List com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(java.lang.String) throws java.io.IOException threw an exception when invoked on com.liferay.portal.tools.servicebuilder.ServiceBuilder@4d4a3cb9
 23     [echo]     at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
 24     [echo]     at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
 25     [echo]     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
 26     [echo]     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
 27     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 28     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 29     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 30     [echo]     at freemarker.core.Environment.visit(Environment.java:310)
 31     [echo]     at freemarker.core.CompressedBlock.accept(CompressedBlock.java:73)
 32     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 33     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 34     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 35     [echo]     at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
 36     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 37     [echo]     at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
 38     [echo]     at freemarker.core.Environment.visit(Environment.java:428)
 39     [echo]     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
 40     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 41     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 42     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 43     [echo]     at freemarker.core.Environment.process(Environment.java:199)
 44     [echo]     at freemarker.template.Template.process(Template.java:237)
 45     [echo]     at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:47)
 46     [echo]     at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:37)
 47     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder._processTemplate(ServiceBuilder.java:4976)
 48     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder._createModelImpl(ServiceBuilder.java:2346)
 49     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:750)
 50     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:228)
 51     [echo] Caused by: java.lang.NullPointerException
 52     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(ServiceBuilder.java:1123)
 53     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 54     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 55     [echo]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 56     [echo]     at java.lang.reflect.Method.invoke(Unknown Source)
 57     [echo]     at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:866)
 58     [echo]     at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
 59     [echo]     ... 27 more
 60     [echo] Method public java.util.List com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(java.lang.String) throws java.io.IOException threw an exception when invoked on com.liferay.portal.tools.servicebuilder.ServiceBuilder@4d4a3cb9
 61     [echo] The problematic instruction:
 62     [echo] ----------
 63     [echo] ==> list serviceBuilder.getMappingEntities(column.mappingTable) as mapColumn [on line 280, column 41 in com/liferay/portal/tools/servicebuilder/dependencies/model_impl.ftl]
 64     [echo] ----------
 65     [echo] Java backtrace for programmers:
 66     [echo] ----------
 67     [echo] freemarker.template.TemplateModelException: Method public java.util.List com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(java.lang.String) throws java.io.IOException threw an exception when invoked on com.liferay.portal.tools.servicebuilder.ServiceBuilder@4d4a3cb9
 68     [echo]     at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
 69     [echo]     at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
 70     [echo]     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
 71     [echo]     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
 72     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 73     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 74     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 75     [echo]     at freemarker.core.Environment.visit(Environment.java:310)
 76     [echo]     at freemarker.core.CompressedBlock.accept(CompressedBlock.java:73)
 77     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 78     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 79     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 80     [echo]     at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
 81     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 82     [echo]     at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
 83     [echo]     at freemarker.core.Environment.visit(Environment.java:428)
 84     [echo]     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
 85     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 86     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 87     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 88     [echo]     at freemarker.core.Environment.process(Environment.java:199)
 89     [echo]     at freemarker.template.Template.process(Template.java:237)
 90     [echo]     at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:47)
 91     [echo]     at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:37)
 92     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder._processTemplate(ServiceBuilder.java:4976)
 93     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder._createModelImpl(ServiceBuilder.java:2346)
 94     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:750)
 95     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:228)
 96     [echo] Caused by: java.lang.NullPointerException
 97     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(ServiceBuilder.java:1123)
 98     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 99     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
100     [echo]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
101     [echo]     at java.lang.reflect.Method.invoke(Unknown Source)
102     [echo]     at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:866)
103     [echo]     at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
104     [echo]     ... 27 more
105    [mkdir] Created dir: E:\Liferay\LIFERAY\liferay-plugins-sdk-6.2\portlets\library-portlet\docroot\WEB-INF\service-classes
106     [copy] Copied 6 empty directories to 6 empty directories under E:\Liferay\LIFERAY\liferay-plugins-sdk-6.2\portlets\library-portlet\docroot\WEB-INF\service-classes
107    [javac] Compiling 30 source files to E:\Liferay\LIFERAY\liferay-plugins-sdk-6.2\portlets\library-portlet\docroot\WEB-INF\service-classes
108      [zip] Building zip: E:\Liferay\LIFERAY\liferay-plugins-sdk-6.2\portlets\library-portlet\docroot\WEB-INF\lib\library-portlet-service.jar
109   [delete] Deleting directory E:\Liferay\LIFERAY\liferay-plugins-sdk-6.2\portlets\library-portlet\docroot\WEB-INF\service-classes
110BUILD SUCCESSFUL
111Total time: 26 seconds
Meera Prince
RE: How to create one to many relationship in Liferay 6.2
June 6, 2014 3:57 AM
Answer

Meera Prince

Rank: Liferay Master

Posts: 814

Join Date: February 8, 2011

Recent Posts

Hi
Refer following thread..

Use Mapping Key. or you can assume Many to Many in one direction then it will be one to many its just my assumption..

Mapping key was deprecated in liferay 6.2

https://www.liferay.com/community/forums/-/message_boards/message/34688498

Have look into following service.xml file of portal have a look into Group entity..


Regards,
Meera Prince
saleem khan
RE: How to create one to many relationship in Liferay 6.2
June 6, 2014 4:07 AM
Answer

saleem khan

Rank: Junior Member

Posts: 42

Join Date: November 15, 2013

Recent Posts

Thanks for replying i have followed to your website and done the necessary editing to my code but get an exception please check the above code and exception which i have update.
saleem khan
RE: How to create one to many relationship in Liferay 6.2
June 6, 2014 5:06 AM
Answer

saleem khan

Rank: Junior Member

Posts: 42

Join Date: November 15, 2013

Recent Posts

i have solved the above exception by giving the package path to the entity and doesnt give any problem but their is new problem now
first consider the code
1
2   <column name="lmsBorrowings" type="Collection"
3                entity="com.slayer.LMSBorrowing" mapping-table="bookId"/>
4    

now the problem is that its not creating the table now,after service building their should be a new table(lms_bookId) but the problem is that the table i not getting created.
please give the solution for this.
thanks
Subhash Pavuskar
RE: How to create one to many relationship in Liferay 6.2
June 6, 2014 5:40 AM
Answer

Subhash Pavuskar

Rank: Regular Member

Posts: 234

Join Date: March 12, 2012

Recent Posts

Hi,
Delete a row from the servicecomponent table and try fresh service build.
saleem khan
RE: How to create one to many relationship in Liferay 6.2
June 7, 2014 7:09 AM
Answer

saleem khan

Rank: Junior Member

Posts: 42

Join Date: November 15, 2013

Recent Posts

thank for replying sir will try out what u said and will update
saleem khan
RE: How to create one to many relationship in Liferay 6.2
June 7, 2014 7:43 AM
Answer

saleem khan

Rank: Junior Member

Posts: 42

Join Date: November 15, 2013

Recent Posts

sir, sir got it working and ur method worked thanks for ur help