Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Peter Hellstrand
Creating many-to-many relationship with existing entites
May 12, 2012 8:18 AM
Answer

Peter Hellstrand

Rank: Regular Member

Posts: 167

Join Date: November 30, 2011

Recent Posts

I am trying this code from the service.xml dtd but i does not work. What do I have to do to use other Entities then those defined in my service.xml.


 1If you are creating a mapping table for an entity defined in another
 2service.xml, you need to specify the full package path.
 3
 4For example:
 5
 6<column
 7    name="organizations"
 8    type="Collection"
 9    entity="com.liferay.portal.Organization"
10    mapping-table="Foo_Organizations"
11/>



  1
  2build-service:
  3     [echo] Loading jar:file:/Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/system.properties
  4     [echo] May 12, 2012 5:12:51 PM com.liferay.portal.kernel.log.Jdk14LogImpl info
  5     [echo] INFO: Global lib directory /Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/lib/ext/
  6     [echo] May 12, 2012 5:12:51 PM com.liferay.portal.kernel.log.Jdk14LogImpl info
  7     [echo] INFO: Portal lib directory /Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/
  8     [echo] 17:12:51,121 INFO  [EasyConf:122] Refreshed the configuration of all components
  9     [echo] 17:12:51,390 INFO  [ConfigurationLoader:56] Properties for jar:file:/Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal loaded from [jar:file:/Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/com/liferay/portal/tools/dependencies/portal-tools.properties, jar:file:/Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties]
 10     [echo] Loading jar:file:/Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties
 11     [echo] Loading jar:file:/Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/com/liferay/portal/tools/dependencies/portal-tools.properties
 12     [echo] Building ImportantNews
 13     [echo] Building Shortcut
 14     [echo] Writing /Users/phe/liferay/liferay-plugins-sdk-6.1.0-ce-ga1-20120106155615760/portlets/jernia-gruppen-portlet/docroot/WEB-INF/src/no/jerniagruppen/services/service/persistence/ShortcutPersistenceImpl.java
 15     [echo] Writing /Users/phe/liferay/liferay-plugins-sdk-6.1.0-ce-ga1-20120106155615760/portlets/jernia-gruppen-portlet/docroot/WEB-INF/service/no/jerniagruppen/services/service/persistence/ShortcutPersistence.java
 16     [echo] Writing /Users/phe/liferay/liferay-plugins-sdk-6.1.0-ce-ga1-20120106155615760/portlets/jernia-gruppen-portlet/docroot/WEB-INF/service/no/jerniagruppen/services/service/persistence/ShortcutUtil.java
 17     [echo] 17:12:56,048 ERROR [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@75e8d4ce"
 18     [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@75e8d4ce
 19     [echo] The problematic instruction:
 20     [echo] ----------
 21     [echo] ==> list serviceBuilder.getMappingEntities(column.mappingTable) as mapColumn [on line 250, column 41 in com/liferay/portal/tools/servicebuilder/dependencies/model_impl.ftl]
 22     [echo] ----------
 23     [echo] Java backtrace for programmers:
 24     [echo] ----------
 25     [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@75e8d4ce
 26     [echo]     at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
 27     [echo]     at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
 28     [echo]     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
 29     [echo]     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
 30     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 31     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 32     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 33     [echo]     at freemarker.core.Environment.visit(Environment.java:310)
 34     [echo]     at freemarker.core.CompressedBlock.accept(CompressedBlock.java:73)
 35     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 36     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 37     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 38     [echo]     at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
 39     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 40     [echo]     at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
 41     [echo]     at freemarker.core.Environment.visit(Environment.java:428)
 42     [echo]     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
 43     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 44     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 45     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 46     [echo]     at freemarker.core.Environment.process(Environment.java:199)
 47     [echo]     at freemarker.template.Template.process(Template.java:237)
 48     [echo]     at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:49)
 49     [echo]     at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:39)
 50     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder._processTemplate(ServiceBuilder.java:4788)
 51     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder._createModelImpl(ServiceBuilder.java:2201)
 52     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:657)
 53     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:430)
 54     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:146)
 55     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 56     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 57     [echo]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 58     [echo]     at java.lang.reflect.Method.invoke(Method.java:597)
 59     [echo]     at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
 60     [echo]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
 61     [echo]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:771)
 62     [echo]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:221)
 63     [echo]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135)
 64     [echo]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
 65     [echo]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
 66     [echo]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
 67     [echo]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 68     [echo]     at java.lang.reflect.Method.invoke(Method.java:597)
 69     [echo]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
 70     [echo]     at org.apache.tools.ant.Task.perform(Task.java:348)
 71     [echo]     at org.apache.tools.ant.Target.execute(Target.java:390)
 72     [echo]     at org.apache.tools.ant.Target.performTasks(Target.java:411)
 73     [echo]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
 74     [echo]     at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
 75     [echo]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
 76     [echo]     at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
 77     [echo]     at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
 78     [echo]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
 79     [echo]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
 80     [echo] Caused by: java.lang.NullPointerException
 81     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(ServiceBuilder.java:1004)
 82     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 83     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 84     [echo]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 85     [echo]     at java.lang.reflect.Method.invoke(Method.java:597)
 86     [echo]     at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:866)
 87     [echo]     at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
 88     [echo]     ... 53 more
 89     [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@75e8d4ce
 90     [echo] The problematic instruction:
 91     [echo] ----------
 92     [echo] ==> list serviceBuilder.getMappingEntities(column.mappingTable) as mapColumn [on line 250, column 41 in com/liferay/portal/tools/servicebuilder/dependencies/model_impl.ftl]
 93     [echo] ----------
 94     [echo] Java backtrace for programmers:
 95     [echo] ----------
 96     [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@75e8d4ce
 97     [echo]     at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
 98     [echo]     at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
 99     [echo]     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
100     [echo]     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
101     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
102     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
103     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
104     [echo]     at freemarker.core.Environment.visit(Environment.java:310)
105     [echo]     at freemarker.core.CompressedBlock.accept(CompressedBlock.java:73)
106     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
107     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
108     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
109     [echo]     at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
110     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
111     [echo]     at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
112     [echo]     at freemarker.core.Environment.visit(Environment.java:428)
113     [echo]     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
114     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
115     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
116     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
117     [echo]     at freemarker.core.Environment.process(Environment.java:199)
118     [echo]     at freemarker.template.Template.process(Template.java:237)
119     [echo]     at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:49)
120     [echo]     at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:39)
121     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder._processTemplate(ServiceBuilder.java:4788)
122     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder._createModelImpl(ServiceBuilder.java:2201)
123     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:657)
124     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:430)
125     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:146)
126     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
127     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
128     [echo]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
129     [echo]     at java.lang.reflect.Method.invoke(Method.java:597)
130     [echo]     at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
131     [echo]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
132     [echo]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:771)
133     [echo]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:221)
134     [echo]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135)
135     [echo]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
136     [echo]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
137     [echo]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
138     [echo]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
139     [echo]     at java.lang.reflect.Method.invoke(Method.java:597)
140     [echo]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
141     [echo]     at org.apache.tools.ant.Task.perform(Task.java:348)
142     [echo]     at org.apache.tools.ant.Target.execute(Target.java:390)
143     [echo]     at org.apache.tools.ant.Target.performTasks(Target.java:411)
144     [echo]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
145     [echo]     at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
146     [echo]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
147     [echo]     at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
148     [echo]     at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
149     [echo]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
150     [echo]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
151     [echo] Caused by: java.lang.NullPointerException
152     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(ServiceBuilder.java:1004)
153     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
154     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
155     [echo]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
156     [echo]     at java.lang.reflect.Method.invoke(Method.java:597)
157     [echo]     at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:866)
158     [echo]     at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
159     [echo]     ... 53 more
Danial Mustofa Habibi
RE: Creating many-to-many relationship with existing entites
May 14, 2012 5:50 AM
Answer

Danial Mustofa Habibi

Rank: Regular Member

Posts: 141

Join Date: November 1, 2011

Recent Posts

Peter Hellstrand:
I am trying this code from the service.xml dtd but i does not work. What do I have to do to use other Entities then those defined in my service.xml.


 1If you are creating a mapping table for an entity defined in another
 2service.xml, you need to specify the full package path.
 3
 4For example:
 5
 6<column
 7    name="organizations"
 8    type="Collection"
 9    entity="com.liferay.portal.Organization"
10    mapping-table="Foo_Organizations"
11/>



  1
  2build-service:
  3     [echo] Loading jar:file:/Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/system.properties
  4     [echo] May 12, 2012 5:12:51 PM com.liferay.portal.kernel.log.Jdk14LogImpl info
  5     [echo] INFO: Global lib directory /Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/lib/ext/
  6     [echo] May 12, 2012 5:12:51 PM com.liferay.portal.kernel.log.Jdk14LogImpl info
  7     [echo] INFO: Portal lib directory /Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/
  8     [echo] 17:12:51,121 INFO  [EasyConf:122] Refreshed the configuration of all components
  9     [echo] 17:12:51,390 INFO  [ConfigurationLoader:56] Properties for jar:file:/Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal loaded from [jar:file:/Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/com/liferay/portal/tools/dependencies/portal-tools.properties, jar:file:/Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties]
 10     [echo] Loading jar:file:/Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties
 11     [echo] Loading jar:file:/Users/phe/liferay/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/com/liferay/portal/tools/dependencies/portal-tools.properties
 12     [echo] Building ImportantNews
 13     [echo] Building Shortcut
 14     [echo] Writing /Users/phe/liferay/liferay-plugins-sdk-6.1.0-ce-ga1-20120106155615760/portlets/jernia-gruppen-portlet/docroot/WEB-INF/src/no/jerniagruppen/services/service/persistence/ShortcutPersistenceImpl.java
 15     [echo] Writing /Users/phe/liferay/liferay-plugins-sdk-6.1.0-ce-ga1-20120106155615760/portlets/jernia-gruppen-portlet/docroot/WEB-INF/service/no/jerniagruppen/services/service/persistence/ShortcutPersistence.java
 16     [echo] Writing /Users/phe/liferay/liferay-plugins-sdk-6.1.0-ce-ga1-20120106155615760/portlets/jernia-gruppen-portlet/docroot/WEB-INF/service/no/jerniagruppen/services/service/persistence/ShortcutUtil.java
 17     [echo] 17:12:56,048 ERROR [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@75e8d4ce"
 18     [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@75e8d4ce
 19     [echo] The problematic instruction:
 20     [echo] ----------
 21     [echo] ==> list serviceBuilder.getMappingEntities(column.mappingTable) as mapColumn [on line 250, column 41 in com/liferay/portal/tools/servicebuilder/dependencies/model_impl.ftl]
 22     [echo] ----------
 23     [echo] Java backtrace for programmers:
 24     [echo] ----------
 25     [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@75e8d4ce
 26     [echo]     at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
 27     [echo]     at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
 28     [echo]     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
 29     [echo]     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
 30     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 31     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 32     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 33     [echo]     at freemarker.core.Environment.visit(Environment.java:310)
 34     [echo]     at freemarker.core.CompressedBlock.accept(CompressedBlock.java:73)
 35     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 36     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 37     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 38     [echo]     at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
 39     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 40     [echo]     at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
 41     [echo]     at freemarker.core.Environment.visit(Environment.java:428)
 42     [echo]     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
 43     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 44     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
 45     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
 46     [echo]     at freemarker.core.Environment.process(Environment.java:199)
 47     [echo]     at freemarker.template.Template.process(Template.java:237)
 48     [echo]     at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:49)
 49     [echo]     at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:39)
 50     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder._processTemplate(ServiceBuilder.java:4788)
 51     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder._createModelImpl(ServiceBuilder.java:2201)
 52     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:657)
 53     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:430)
 54     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:146)
 55     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 56     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 57     [echo]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 58     [echo]     at java.lang.reflect.Method.invoke(Method.java:597)
 59     [echo]     at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
 60     [echo]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
 61     [echo]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:771)
 62     [echo]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:221)
 63     [echo]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135)
 64     [echo]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
 65     [echo]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
 66     [echo]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
 67     [echo]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 68     [echo]     at java.lang.reflect.Method.invoke(Method.java:597)
 69     [echo]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
 70     [echo]     at org.apache.tools.ant.Task.perform(Task.java:348)
 71     [echo]     at org.apache.tools.ant.Target.execute(Target.java:390)
 72     [echo]     at org.apache.tools.ant.Target.performTasks(Target.java:411)
 73     [echo]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
 74     [echo]     at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
 75     [echo]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
 76     [echo]     at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
 77     [echo]     at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
 78     [echo]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
 79     [echo]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
 80     [echo] Caused by: java.lang.NullPointerException
 81     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(ServiceBuilder.java:1004)
 82     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 83     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 84     [echo]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 85     [echo]     at java.lang.reflect.Method.invoke(Method.java:597)
 86     [echo]     at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:866)
 87     [echo]     at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
 88     [echo]     ... 53 more
 89     [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@75e8d4ce
 90     [echo] The problematic instruction:
 91     [echo] ----------
 92     [echo] ==> list serviceBuilder.getMappingEntities(column.mappingTable) as mapColumn [on line 250, column 41 in com/liferay/portal/tools/servicebuilder/dependencies/model_impl.ftl]
 93     [echo] ----------
 94     [echo] Java backtrace for programmers:
 95     [echo] ----------
 96     [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@75e8d4ce
 97     [echo]     at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
 98     [echo]     at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
 99     [echo]     at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
100     [echo]     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
101     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
102     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
103     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
104     [echo]     at freemarker.core.Environment.visit(Environment.java:310)
105     [echo]     at freemarker.core.CompressedBlock.accept(CompressedBlock.java:73)
106     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
107     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
108     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
109     [echo]     at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
110     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
111     [echo]     at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
112     [echo]     at freemarker.core.Environment.visit(Environment.java:428)
113     [echo]     at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
114     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
115     [echo]     at freemarker.core.MixedContent.accept(MixedContent.java:92)
116     [echo]     at freemarker.core.Environment.visit(Environment.java:221)
117     [echo]     at freemarker.core.Environment.process(Environment.java:199)
118     [echo]     at freemarker.template.Template.process(Template.java:237)
119     [echo]     at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:49)
120     [echo]     at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:39)
121     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder._processTemplate(ServiceBuilder.java:4788)
122     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder._createModelImpl(ServiceBuilder.java:2201)
123     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:657)
124     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:430)
125     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:146)
126     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
127     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
128     [echo]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
129     [echo]     at java.lang.reflect.Method.invoke(Method.java:597)
130     [echo]     at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
131     [echo]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
132     [echo]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:771)
133     [echo]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:221)
134     [echo]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135)
135     [echo]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
136     [echo]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
137     [echo]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
138     [echo]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
139     [echo]     at java.lang.reflect.Method.invoke(Method.java:597)
140     [echo]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
141     [echo]     at org.apache.tools.ant.Task.perform(Task.java:348)
142     [echo]     at org.apache.tools.ant.Target.execute(Target.java:390)
143     [echo]     at org.apache.tools.ant.Target.performTasks(Target.java:411)
144     [echo]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
145     [echo]     at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
146     [echo]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
147     [echo]     at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
148     [echo]     at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
149     [echo]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
150     [echo]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
151     [echo] Caused by: java.lang.NullPointerException
152     [echo]     at com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(ServiceBuilder.java:1004)
153     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
154     [echo]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
155     [echo]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
156     [echo]     at java.lang.reflect.Method.invoke(Method.java:597)
157     [echo]     at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:866)
158     [echo]     at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
159     [echo]     ... 53 more

can you post your service.xml??
here some example
 1<entity name="Parent" local-service="true" remote-service="false">
 2
 3<column name="parentId" type="long" primary="true" />
 4 <column name="childId" type="Collection" entity="Child" mapping-key="childId"/>
 5
 6
 7</entity>
 8
 9
10
11<entity name="Child" local-service="true" remote-service="false">
12
13<column name="childId" type="long" primary="true" />
14
15<column name="parentId" type="Collections" entity="Parent" mapping-key="parentId" />
16
17</entity>

hope this help
Giuseppe Pantaleo
RE: Creating many-to-many relationship with existing entites
June 29, 2012 5:28 AM
Answer

Giuseppe Pantaleo

Rank: New Member

Posts: 15

Join Date: June 18, 2012

Recent Posts

I'm experiencing the same problem; have you solved it?
Here is service.xml file:
Attachments: service.xml (1.4k)
Robson SARAIVA Ximenes
RE: Creating many-to-many relationship with existing entites
October 30, 2012 11:18 AM
Answer

Robson SARAIVA Ximenes

Rank: New Member

Posts: 10

Join Date: June 18, 2012

Recent Posts

Same error on my stack trace;

 1
 2<?xml version="1.0" encoding="UTF-8"?>
 3<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
 4<service-builder package-path="br.catalogo">
 5    <author></author>
 6    <namespace>CAT</namespace>
 7    <entity name="Categoria" local-service="true" remote-service="false">
 8        <!-- PK fields -->
 9        <column name="categoriaId" type="long" primary="true" />
10        <!-- Group instance -->
11        <column name="groupId" type="long" />
12        <!-- Audit fields -->
13        <column name="companyId" type="long" />
14        <column name="userId" type="long" />
15        <column name="userName" type="String" />
16        <column name="createDate" type="Date" />
17        <column name="modifiedDate" type="Date" />
18       
19        <!-- Other fields -->
20        <column name="nome" type="String" />
21        <column name="descricao" type="String" />
22       
23        <!-- Order -->
24        <order by="asc">
25            <order-column name="nome" case-sensitive="false" />
26        </order>       
27    </entity>
28
29    <entity name="Aplicativo" local-service="true" remote-service="false">
30        <!-- PK fields -->
31        <column name="aplicativoId" type="long" primary="true" />
32        <!-- Group instance -->
33        <column name="groupId" type="long" />
34        <!-- Audit fields -->
35        <column name="companyId" type="long" />
36        <column name="userId" type="long" />
37        <column name="userName" type="String" />
38        <column name="createDate" type="Date" />
39        <column name="modifiedDate" type="Date" />
40
41        <!-- Other fields -->
42        <column name="nome" type="String" />
43        <column name="descricao" type="String" />
44       
45        <!-- Relationships -->
46        <column name="categorias" type="Collection" entity="Categoria" mapping-table="aplicativo_categoria" />
47        <!-- Fala adicionar: plataformas -->
48       
49        <!-- Order -->
50        <order by="asc">
51            <order-column name="nome" case-sensitive="false" />
52        </order>       
53    </entity>   
54</service-builder>


The problem happens because of
<column name="categorias" type="Collection" entity="Categoria" mapping-table="aplicativo_categoria" />

I tried some variations:
1<column name="categorias" type="Collection" entity="Categoria" mapping-table="Aplicativo_Categoria" />

<column name="categorias" type="Collection" entity="Categoria" mapping-table="Aplicativos_Categorias" />

<column name="categorias" type="Collection" entity="Categoria" mapping-table="aplicativos_categoria"s />


All with same erro...
Attachments: service.xml (2.3k)
Michele Zanarotti
RE: Creating many-to-many relationship with existing entites
January 31, 2013 2:44 AM
Answer

Michele Zanarotti

Rank: Junior Member

Posts: 93

Join Date: February 20, 2012

Recent Posts

Hello. Have you find any solution yet ?

Basically i don't understand if I have to create the relational table by myself, or Liferay will generate a new Table with the given mapping-table name.
Cesar Alvarez
RE: Creating many-to-many relationship with existing entites
June 19, 2013 10:09 PM
Answer

Cesar Alvarez

Rank: New Member

Posts: 3

Join Date: May 19, 2013

Recent Posts

I was just having the same issue and stumbled upon this thread ... I was able to fix it by actually putting the package name before the entity

<column name="categorias" type="Collection" entity="br.catalogo.Categoria" mapping-table="aplicativo_categoria" />


Not sure why this happens if they're in the same file.
suresh R
RE: Creating many-to-many relationship with existing entites
June 20, 2013 5:08 AM
Answer

suresh R

Rank: New Member

Posts: 18

Join Date: June 13, 2013

Recent Posts

Hi Peter,

liferay source for all service.xml and look for keywords: mapping-key (for one to many) and mapping-table (for many to many) relations.

Example service.xml taken from: \liferay-portal-src-5.0.1\portal-impl\src\com\liferay\portlet\shopping :


<entity name="ShoppingItem" local-service="true" remote-service="true">

<!-- PK fields -->

<column name="itemId" type="long" primary="true" />

<!-- Audit fields -->

<column name="companyId" type="long" />
<column name="userId" type="long" />
<column name="userName" type="String" />
<column name="createDate" type="Date" />
<column name="modifiedDate" type="Date" />

<!-- Other fields -->

<column name="categoryId" type="long" />
<column name="sku" type="String" />
<column name="name" type="String" />
<column name="description" type="String" />
<column name="properties" type="String" />
<column name="fields" type="boolean" />
<column name="fieldsQuantities" type="String" />
<column name="minQuantity" type="int" />
<column name="maxQuantity" type="int" />
<column name="price" type="double" />
<column name="discount" type="double" />
<column name="taxable" type="boolean" />
<column name="shipping" type="double" />
<column name="useShippingFormula" type="boolean" />
<column name="requiresShipping" type="boolean" />
<column name="stockQuantity" type="int" />
<column name="featured" type="boolean" />
<column name="sale" type="boolean" />
<column name="smallImage" type="boolean" />
<column name="smallImageId" type="long" />
<column name="smallImageURL" type="String" />
<column name="mediumImage" type="boolean" />
<column name="mediumImageId" type="long" />
<column name="mediumImageURL" type="String" />
<column name="largeImage" type="boolean" />
<column name="largeImageId" type="long" />
<column name="largeImageURL" type="String" />

<!-- Relationships -->

<column name="shoppingItemPrices" type="Collection" entity="ShoppingItemPrice" mapping-key="itemId" />

and then you have reference entity ShoppingItemPrice:

<entity name="ShoppingItemPrice" local-service="true" remote-service="false">

<!-- PK fields -->

<column name="itemPriceId" type="long" primary="true" />

<!-- Other fields -->

<column name="itemId" type="long" />
<column name="minQuantity" type="int" />
<column name="maxQuantity" type="int" />
<column name="price" type="double" />
<column name="discount" type="double" />
<column name="taxable" type="boolean" />
<column name="shipping" type="double" />
<column name="useShippingFormula" type="boolean" />
<column name="status" type="int" />

As I understand this, for me this is one to one relationship, but type="Collection" states that result might contain more than one price for an item. Strange, but that's how they designed it.

In this particular example, considering relation from main table to the second one using itemId which is not PK, it would be wise to add a finder (I am not sure if it's necessary), but finder will help you search items on foreign key, which is here itemId (generated classes has only searching by primary key which is here priceId, and will not help you much). Therefore they also created one finder:
<!-- Finder methods -->

<finder name="ItemId" return-type="Collection">
<finder-column name="itemId" />
</finder>


But, before you dive into this example, I have seen that there are not many relations in liferay table. Instead they use table classname_ that has list of classes.

So for example: in lportal.address table, there is a field classNameId, that is usually 10034 (in my instalation) and stands for com.liferay.portal.model.User and then classPK is the primary key of mentioned table, which means that this is an address of user with id 18206 (in my case). And indeed, user 18206 does exist.

This is not classical relationship, but indeed something that you should be aware of. Search forum for classPK and classNameId to get more inspiration.

Also note that this classes_ table is updated when you use ext environment and that class names are added automatically there, so your entities (tables) will be there.
By using of this code you can get idea.
I shared what I know about this.

Thanks,
Suresh