留言板

Service Builder exception using mapping table

Bob Dietrich,修改在9 年前。

Service Builder exception using mapping table

Regular Member 帖子: 221 加入日期: 05-5-16 最近的帖子
I'm seeing an exception when trying to add a mapping table so I can create a one-many relationship. Here's the exception trace:
Buildfile: C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\build.xml
build-service:
      [jar] Building MANIFEST-only jar: C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\build-service-classpath.jar
   [delete] Deleting: C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\build-service-classpath.jar.manifest
   [delete] Deleting: C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\build-service-classpath.jar
     [echo] Loading jar:file:/C:/Build/Liferay6.2GA2/tomcat/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/system.properties
     [echo] Loading jar:file:/C:/Build/Liferay6.2GA2/tomcat/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties
     [echo] Loading jar:file:/C:/Build/Liferay6.2GA2/tomcat/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/com/liferay/portal/tools/dependencies/portal-tools.properties
     [echo] Building Foo
     [echo] 02:44:29,386 ERROR [main][runtime:96] Template processing error: "Method public com.liferay.portal.tools.servicebuilder.Entity com.liferay.portal.tools.servicebuilder.ServiceBuilder.getEntity(java.lang.String) throws java.io.IOException threw an exception when invoked on com.liferay.portal.tools.servicebuilder.ServiceBuilder@717446a2"
     [echo] Method public com.liferay.portal.tools.servicebuilder.Entity com.liferay.portal.tools.servicebuilder.ServiceBuilder.getEntity(java.lang.String) throws java.io.IOException threw an exception when invoked on com.liferay.portal.tools.servicebuilder.ServiceBuilder@717446a2
     [echo] The problematic instruction:
     [echo] ----------
     [echo] Method public com.liferay.portal.tools.servicebuilder.Entity com.liferay.portal.tools.servicebuilder.ServiceBuilder.getEntity(java.lang.String) throws java.io.IOException threw an exception when invoked on com.liferay.portal.tools.servicebuilder.ServiceBuilder@717446a2
     [echo] The problematic instruction:
     [echo] ----------
     [echo] ==> assignment: tempEntity=serviceBuilder.getEntity(column.getEJBName()) [on line 420, column 33 in com/liferay/portal/tools/servicebuilder/dependencies/persistence_impl.ftl]==> assignment: tempEntity=serviceBuilder.getEntity(column.getEJBName()) [on line 420, column 33 in com/liferay/portal/tools/servicebuilder/dependencies/persistence_impl.ftl]
     [echo] --------------------
     [echo] Java backtrace for programmers:
     [echo] ----------
     [echo] Java backtrace for programmers:
     [echo] ----------
     [echo] freemarker.template.TemplateModelException: Method public com.liferay.portal.tools.servicebuilder.Entity com.liferay.portal.tools.servicebuilder.ServiceBuilder.getEntity(java.lang.String) throws java.io.IOException threw an exception when invoked on com.liferay.portal.tools.servicebuilder.ServiceBuilder@717446a2
     [echo] 	at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)freemarker.template.TemplateModelException: Method public com.liferay.portal.tools.servicebuilder.Entity com.liferay.portal.tools.servicebuilder.ServiceBuilder.getEntity(java.lang.String) throws java.io.IOException threw an exception when invoked on com.liferay.portal.tools.servicebuilder.ServiceBuilder@717446a2
     [echo] 	at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
     [echo] 	at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
     [echo] 	at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)	at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
     [echo] 	at freemarker.core.Assignment.accept(Assignment.java:90)
     [echo] 	at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)	at freemarker.core.Environment.visit(Environment.java:221)
     [echo] 	at freemarker.core.MixedContent.accept(MixedContent.java:92)	at freemarker.core.Assignment.accept(Assignment.java:90)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:221)	at freemarker.core.Environment.visit(Environment.java:221)
     [echo] 	at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)	at freemarker.core.MixedContent.accept(MixedContent.java:92)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:221)	at freemarker.core.Environment.visit(Environment.java:221)
     [echo] 	at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)	at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:428)	at freemarker.core.Environment.visit(Environment.java:221)
     [echo] 	at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)	at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:221)	at freemarker.core.Environment.visit(Environment.java:428)
     [echo] 	at freemarker.core.MixedContent.accept(MixedContent.java:92)	at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:221)	at freemarker.core.Environment.visit(Environment.java:221)
     [echo] 	at freemarker.core.Environment.process(Environment.java:199)	at freemarker.core.MixedContent.accept(MixedContent.java:92)
     [echo] 	at freemarker.template.Template.process(Template.java:237)	at freemarker.core.Environment.visit(Environment.java:221)
     [echo] 	at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:47)	at freemarker.core.Environment.process(Environment.java:199)
     [echo] 	at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:37)	at freemarker.template.Template.process(Template.java:237)
     [echo] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder._processTemplate(ServiceBuilder.java:4976)	at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:47)
     [echo] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder._createPersistenceImpl(ServiceBuilder.java:2575)	at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:37)
     [echo] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:742)	at com.liferay.portal.tools.servicebuilder.ServiceBuilder._processTemplate(ServiceBuilder.java:4976)
     [echo] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:228)	at com.liferay.portal.tools.servicebuilder.ServiceBuilder._createPersistenceImpl(ServiceBuilder.java:2575)
     [echo] Caused by: java.lang.NullPointerException
     [echo] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:742)	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.getEntity(ServiceBuilder.java:952)
     [echo] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:228)
     [echo] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)Caused by: java.lang.NullPointerException
     [echo] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.getEntity(ServiceBuilder.java:952)	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     [echo] 	at java.lang.reflect.Method.invoke(Method.java:606)
     [echo] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)	at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:866)
     [echo] 	at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
     [echo] 	... 22 more
     [echo] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     [echo] 	at java.lang.reflect.Method.invoke(Method.java:606)
     [echo] 	at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:866)
     [echo] 	at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
     [echo] 	... 22 more
    [mkdir] Created dir: C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\docroot\WEB-INF\service-classes
     [copy] Copied 7 empty directories to 7 empty directories under C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\docroot\WEB-INF\service-classes
    [javac] Compiling 53 source files to C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\docroot\WEB-INF\service-classes
      [zip] Building zip: C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\docroot\WEB-INF\lib\test-portlet-service.jar
   [delete] Deleting directory C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\docroot\WEB-INF\service-classes
BUILD SUCCESSFUL
Total time: 9 seconds
</init></init>

I'm using Win8 64 bit, and just downloaded Liferay IDE win64 2.1.1ga2.

Here are the steps to reproduce.
  • Create a new Service Builder project with sample data
  • Create a new entity called FooBar in the service.xml file with default columns.
  • Add a field to Foo called fooBarList with type Collection.
  • Build the services (build-service). No errors.
  • Add a mapping table entry to fooBarList (something like Foo_FooBar).
  • Build the services again. The error above will occur.
  • Remove the mapping table entry and the build will succeed.

For completeness, here is the final service.xml file:
*Edit 8/29/2014: Included the entity attribute left out*
<!--?xml version="1.0" encoding="UTF-8"?-->

<service-builder package-path="com.liferay.sample">
	<author>Bob</author>
	<namespace>SAMPLE</namespace>

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

		<!-- PK fields -->

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

		<!-- Group instance -->

		<column name="groupId" type="long" />

		<!-- 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="field1" type="String" />
		<column name="field2" type="boolean" />
		<column name="field3" type="int" />
		<column name="field4" type="Date" />
		<column name="field5" type="String" />

		<!-- Order -->
        <!-- Original posting had this:
        <column name="fooBarList" type="Collection" mapping-table="Foo_FooBar"></column>
        Correct entry is this: -->
        <column name="fooBarList" type="Collection" entity="FooBar" mapping-table="Foo_FooBar"></column>

		<order by="asc">
			<order-column name="field1" />
		</order>

		<!-- Finder methods -->

		<finder name="Field2" return-type="Collection">
			<finder-column name="field2" />
		</finder>
	</entity>
	<entity name="FooBar" local-service="true">

		<!-- PK fields -->

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

		<!-- Group instance -->

		<column name="groupId" type="long"></column>

		<!-- Audit fields -->

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

Suggestions? Thanks.
thumbnail
David H Nebinger,修改在9 年前。

RE: Service Builder exception using mapping table

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
With the mapping-table attribute, you also need the entity attribute so SB will know what entity the collection contains.
Bob Dietrich,修改在9 年前。

RE: Service Builder exception using mapping table

Regular Member 帖子: 221 加入日期: 05-5-16 最近的帖子
Thanks for the reply. I did actually have the entity attribute, but forgot to include in my cut-down example for posting. Here is the resulting entry for fooBarList and the build exception:
From service.xml:
        <column name="fooBarList" type="Collection" entity="FooBar" mapping-table="Foo_FooBar"></column>

The build:
Buildfile: C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\build.xml
build-service:
      [jar] Building MANIFEST-only jar: C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\build-service-classpath.jar
   [delete] Deleting: C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\build-service-classpath.jar.manifest
   [delete] Deleting: C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\build-service-classpath.jar
     [echo] Loading jar:file:/C:/Build/Liferay6.2GA2/tomcat/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/system.properties
     [echo] Loading jar:file:/C:/Build/Liferay6.2GA2/tomcat/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties
     [echo] Loading jar:file:/C:/Build/Liferay6.2GA2/tomcat/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/com/liferay/portal/tools/dependencies/portal-tools.properties
     [echo] Building Foo
     [echo] Writing C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\docroot\WEB-INF\src\com\liferay\sample\service\persistence\FooPersistenceImpl.java
     [echo] Writing C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\docroot\WEB-INF\service\com\liferay\sample\service\persistence\FooPersistence.java
     [echo] Writing C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\docroot\WEB-INF\service\com\liferay\sample\service\persistence\FooUtil.java
     [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@60a77a79
     [echo] The problematic instruction:
     [echo] ----------
     [echo] ==&gt; list serviceBuilder.getMappingEntities(column.mappingTable) as mapColumn [on line 280, column 41 in com/liferay/portal/tools/servicebuilder/dependencies/model_impl.ftl]
     [echo] ----------
     [echo] Java backtrace for programmers:
     [echo] ----------
     [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@60a77a79
     [echo] 	at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
     [echo] 	at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
     [echo] 	at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
     [echo] 	at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:221)
     [echo] 	at freemarker.core.MixedContent.accept(MixedContent.java:92)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:221)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:310)
     [echo] 	at freemarker.core.CompressedBlock.accept(CompressedBlock.java:73)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:221)
     [echo] 	at freemarker.core.MixedContent.accept(MixedContent.java:92)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:221)14:54:35,172 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@60a77a79"
     [echo] 	at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:221)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@60a77a79
     [echo] The problematic instruction:	at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
     [echo] ----------
     [echo] 	at freemarker.core.Environment.visit(Environment.java:428)
     [echo] 	at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)==&gt; list serviceBuilder.getMappingEntities(column.mappingTable) as mapColumn [on line 280, column 41 in com/liferay/portal/tools/servicebuilder/dependencies/model_impl.ftl]
     [echo] ----------	at freemarker.core.Environment.visit(Environment.java:221)
     [echo] Java backtrace for programmers:
     [echo] ----------
     [echo] 	at freemarker.core.MixedContent.accept(MixedContent.java:92)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:221)
     [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@60a77a79	at freemarker.core.Environment.process(Environment.java:199)
     [echo] 	at freemarker.template.Template.process(Template.java:237)	at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
     [echo] 	at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)	at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:47)
     [echo] 	at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:37)	at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
     [echo] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder._processTemplate(ServiceBuilder.java:4976)	at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:221)	at com.liferay.portal.tools.servicebuilder.ServiceBuilder._createModelImpl(ServiceBuilder.java:2346)
     [echo] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:750)	at freemarker.core.MixedContent.accept(MixedContent.java:92)
     [echo] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:228)	at freemarker.core.Environment.visit(Environment.java:221)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:310)Caused by: java.lang.NullPointerException
     [echo] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(ServiceBuilder.java:1123)	at freemarker.core.CompressedBlock.accept(CompressedBlock.java:73)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:221)	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [echo] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)	at freemarker.core.MixedContent.accept(MixedContent.java:92)
     [echo] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)	at freemarker.core.Environment.visit(Environment.java:221)
     [echo] 	at java.lang.reflect.Method.invoke(Method.java:606)	at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
     [echo] 	at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:866)	at freemarker.core.Environment.visit(Environment.java:221)
     [echo] 	at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)	at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
     [echo] 	... 27 more
     [echo] 	at freemarker.core.Environment.visit(Environment.java:428)
     [echo] 	at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:221)
     [echo] 	at freemarker.core.MixedContent.accept(MixedContent.java:92)
     [echo] 	at freemarker.core.Environment.visit(Environment.java:221)
     [echo] 	at freemarker.core.Environment.process(Environment.java:199)
     [echo] 	at freemarker.template.Template.process(Template.java:237)
     [echo] 	at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:47)
     [echo] 	at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:37)
     [echo] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder._processTemplate(ServiceBuilder.java:4976)
     [echo] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder._createModelImpl(ServiceBuilder.java:2346)
     [echo] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:750)
     [echo] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:228)
     [echo] Caused by: java.lang.NullPointerException
     [echo] 	at com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(ServiceBuilder.java:1123)
     [echo] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [echo] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
     [echo] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     [echo] 	at java.lang.reflect.Method.invoke(Method.java:606)
     [echo] 	at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:866)
     [echo] 	at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
     [echo] 	... 27 more
    [mkdir] Created dir: C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\docroot\WEB-INF\service-classes
     [copy] Copied 7 empty directories to 7 empty directories under C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\docroot\WEB-INF\service-classes
    [javac] Compiling 53 source files to C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\docroot\WEB-INF\service-classes
      [zip] Building zip: C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\docroot\WEB-INF\lib\test-portlet-service.jar
   [delete] Deleting directory C:\Build\Liferay6.2GA2\sdk\portlets\test-portlet\docroot\WEB-INF\service-classes
BUILD SUCCESSFUL
Total time: 10 seconds</init></init>
thumbnail
David H Nebinger,修改在9 年前。

RE: Service Builder exception using mapping table

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
The only way this can happen is if somehow the mapping tables that SB is maintaining does not have a value for the mapping table (which it has already parsed and used in the construction of the column object).

Can you try a clean build to eliminate any old artifacts that might be getting in the way?
Bob Dietrich,修改在9 年前。

RE: Service Builder exception using mapping table

Regular Member 帖子: 221 加入日期: 05-5-16 最近的帖子
No joy. I created a new project, added the FooBar entity, and copied the definition of fooBarList into service.xml. Once I had done this, I tried building (build-service), not before. The build failed due to the exception above and failed to create most of the artifacts. I then removed the mapping table attribute and was able to build successfully.
thumbnail
David H Nebinger,修改在9 年前。

RE: Service Builder exception using mapping table

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
Oh, what a nasty, nasty little bug this one is...

Basically it boils down to this chunk of code beginning around line 4689:

EntityMapping entityMapping = new EntityMapping(
	mappingTable, ejbName, collectionEntity);

int ejbNameWeight = StringUtil.startsWithWeight(
	mappingTable, ejbName);
int collectionEntityWeight = StringUtil.startsWithWeight(
	mappingTable, collectionEntity);

if ((ejbNameWeight &gt; collectionEntityWeight) ||
	((ejbNameWeight == collectionEntityWeight) &amp;&amp;
	 (ejbName.compareTo(collectionEntity) &gt; 0))) {

	_entityMappings.put(mappingTable, entityMapping);
}


Based off of your service.xml, you get the following values:

ejbName = Foo
collectionEntity = FooBar
mappingTable = Bob_Foo_FooBar
ejbNameWeight = 0
coolectionEntityWeight = 0
ejbName.compareTo(collectionEntity) < 0 (Foo would come before FooBar lexicographically)

Now, because I think the whole name comparison thing is a bug, it is never added to the _entityMappings map, and therefore the getMappingEntities() fails because the EntityMapping element is null and therefore the lines at 1123:

EntityMapping entityMapping = _entityMappings.get(mappingTable);

for (int i = 0; i &lt; 2; i++) {
	Entity entity = getEntity(entityMapping.getEntity(i));

	if (entity == null) {
		return null;
	}

	mappingEntitiesPKList.addAll(entity.getPKList());
}


ends up throwing an NPE because entityMapping is a null object because it is not in the map.

Long story short, I'm sure this is some kind of bug, but I'm not sure what Liferay should do to fix it. You should definitely open a bug on it so it gets recorded.

Short term, however, if you change entity name FooBar to something that lexicographically comes before Foo, it will compile and work just fine.
thumbnail
David H Nebinger,修改在9 年前。

RE: Service Builder exception using mapping table

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
BTW, +1 for providing enough info to identify the problem and propose a solution! emoticon
Bob Dietrich,修改在9 年前。

RE: Service Builder exception using mapping table

Regular Member 帖子: 221 加入日期: 05-5-16 最近的帖子
David, thanks for investigating. It's definitely a strange and curious bug. I created yet another project, but this time called the new entity AFooBar instead of FooBar so that it would sort before Foo. The service build worked. However, it appears the code generated for FooLocalServiceBaseImpl has errors. I don't have time to investigate right now.

Perhaps I should have name the entities FUBAR.
Bob Dietrich,修改在9 年前。

RE: Service Builder exception using mapping table

Regular Member 帖子: 221 加入日期: 05-5-16 最近的帖子
OK, I finally got back to this. As I stated earlier, changing the entity name to sort less than the parent entity stopped SB from having exceptions. However, the code that's generated now has problems - references to undefined (not generated) methods:
c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet&gt;ant clean build-service deploy
Buildfile: c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\build.xml

clean:
   [delete] Deleting directory c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\classes
   [delete] Deleting: c:\Build\Liferay6.2GA2\sdk\dist\test3-portlet-6.2.0.1.war

build-service:
    [mkdir] Created dir: c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\classes
     [copy] Copying 10 files to c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\classes
     [copy] Copied 11 empty directories to 10 empty directories under c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\classes
      [jar] Building MANIFEST-only jar: c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\build-service-classpath.jar
   [delete] Deleting: c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\build-service-classpath.jar.manifest
   [delete] Deleting: c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\build-service-classpath.jar
     [echo] Loading jar:file:/C:/Build/Liferay6.2GA2/tomcat/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/system.properties
     [echo] Loading jar:file:/C:/Build/Liferay6.2GA2/tomcat/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties
     [echo] Loading jar:file:/C:/Build/Liferay6.2GA2/tomcat/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/com/liferay/portal/tools/dependencies/portal-tools.properties
     [echo] Building AFooBar
     [echo] Writing c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\service\com\liferay\sample\model\AFooBarWrapper.java
     [echo] Building Foo
     [echo] Writing c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\service\com\liferay\sample\model\FooWrapper.java
    [mkdir] Created dir: c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\service-classes
     [copy] Copied 7 empty directories to 7 empty directories under c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\service-classes
    [javac] Compiling 36 source files to c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\service-classes
      [zip] Building zip: c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\lib\test3-portlet-service.jar
   [delete] Deleting directory c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\service-classes

deploy:
     [copy] Copying 5 files to c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\lib
     [copy] Copying 1 file to c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\classes
    [javac] Compiling 24 source files to c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\classes
    [javac] ----------
    [javac] 1. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 280)
    [javac]     aFooBarPersistence.addFoo(aFooBarId, fooId);
    [javac]                        ^^^^^^
    [javac] The method addFoo(long, long) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 2. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 289)
    [javac]     aFooBarPersistence.addFoo(aFooBarId, foo);
    [javac]                        ^^^^^^
    [javac] The method addFoo(long, Foo) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 3. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 298)
    [javac]     aFooBarPersistence.addFoos(aFooBarId, fooIds);
    [javac]                        ^^^^^^^
    [javac] The method addFoos(long, long[]) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 4. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 307)
    [javac]     aFooBarPersistence.addFoos(aFooBarId, Foos);
    [javac]                        ^^^^^^^
    [javac] The method addFoos(long, List<foo>) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 5. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 315)
    [javac]     aFooBarPersistence.clearFoos(aFooBarId);
    [javac]                        ^^^^^^^^^
    [javac] The method clearFoos(long) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 6. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 324)
    [javac]     aFooBarPersistence.removeFoo(aFooBarId, fooId);
    [javac]                        ^^^^^^^^^
    [javac] The method removeFoo(long, long) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 7. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 333)
    [javac]     aFooBarPersistence.removeFoo(aFooBarId, foo);
    [javac]                        ^^^^^^^^^
    [javac] The method removeFoo(long, Foo) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 8. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 342)
    [javac]     aFooBarPersistence.removeFoos(aFooBarId, fooIds);
    [javac]                        ^^^^^^^^^^
    [javac] The method removeFoos(long, long[]) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 9. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 351)
    [javac]     aFooBarPersistence.removeFoos(aFooBarId, Foos);
    [javac]                        ^^^^^^^^^^
    [javac] The method removeFoos(long, List<foo>) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 10. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 359)
    [javac]     return aFooBarPersistence.getFoos(aFooBarId);
    [javac]                               ^^^^^^^
    [javac] The method getFoos(long) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 11. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 368)
    [javac]     return aFooBarPersistence.getFoos(aFooBarId, start, end);
    [javac]                               ^^^^^^^
    [javac] The method getFoos(long, int, int) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 12. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 377)
    [javac]     return aFooBarPersistence.getFoos(aFooBarId, start, end,
    [javac]                               ^^^^^^^
    [javac] The method getFoos(long, int, int, OrderByComparator) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 13. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 386)
    [javac]     return aFooBarPersistence.getFoosSize(aFooBarId);
    [javac]                               ^^^^^^^^^^^
    [javac] The method getFoosSize(long) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 14. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 395)
    [javac]     return aFooBarPersistence.containsFoo(aFooBarId, fooId);
    [javac]                               ^^^^^^^^^^^
    [javac] The method containsFoo(long, long) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 15. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 403)
    [javac]     return aFooBarPersistence.containsFoos(aFooBarId);
    [javac]                               ^^^^^^^^^^^^
    [javac] The method containsFoos(long) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 16. ERROR in c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet\docroot\WEB-INF\src\com\liferay\sample\service\base\FooLocalServiceBaseImpl.java (at line 412)
    [javac]     aFooBarPersistence.setFoos(aFooBarId, fooIds);
    [javac]                        ^^^^^^^
    [javac] The method setFoos(long, long[]) is undefined for the type AFooBarPersistence
    [javac] ----------
    [javac] 16 problems (16 errors)

BUILD FAILED
c:\Build\Liferay6.2GA2\sdk\build-common-plugin.xml:482: The following error occurred while executing this line:
c:\Build\Liferay6.2GA2\sdk\build-common.xml:993: The following error occurred while executing this line:
c:\Build\Liferay6.2GA2\sdk\build-common.xml:299: The following error occurred while executing this line:
c:\Build\Liferay6.2GA2\sdk\build-common.xml:1762: The following error occurred while executing this line:
c:\Build\Liferay6.2GA2\sdk\build-common.xml:219: The following error occurred while executing this line:
c:\Build\Liferay6.2GA2\sdk\build-common.xml:465: The following error occurred while executing this line:
c:\Build\Liferay6.2GA2\sdk\build-common.xml:747: The following error occurred while executing this line:
c:\Build\Liferay6.2GA2\sdk\build-common.xml:634: Compile failed; see the compiler error output for details.

Total time: 11 seconds

c:\Build\Liferay6.2GA2\sdk\portlets\test3-portlet&gt;
</foo></foo>

Just for the record, I followed the steps outlined above and did not add any code to the implementation.

I will create a couple of issues in JIRA.
Bob Dietrich,修改在9 年前。

RE: Service Builder exception using mapping table

Regular Member 帖子: 221 加入日期: 05-5-16 最近的帖子
thumbnail
Gregory Amerson,修改在9 年前。

RE: Service Builder exception using mapping table

Liferay Legend 帖子: 1123 加入日期: 10-2-16 最近的帖子
Hello Bob,

Thanks for this bug report. I've moved it to the LPS project (Liferay Portal) project and targeted the service builder component. Also I've moved this thread out of IDE and into the Portal development category in order to give it more visibility to the core engineers. Thanks again for your report.
thumbnail
Gregory Amerson,修改在9 年前。

RE: Service Builder exception using mapping table

Liferay Legend 帖子: 1123 加入日期: 10-2-16 最近的帖子
Here is the location of the moved issue: https://issues.liferay.com/browse/LPS-49769
Premek Steidl,修改在9 年前。

RE: Service Builder exception using mapping table

New Member 帖子: 10 加入日期: 12-10-18 最近的帖子
Hi,
is there any progress or workaround for this issue?
I'm creating a portlet with custom entities and I'm not able to create a relation between my entity and existing liferay entity (fe. Organization)

Thank You for any help.
thumbnail
David H Nebinger,修改在9 年前。

RE: Service Builder exception using mapping table

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
You should not create relationships to liferay's entities outside of storing the PK and retrieving using their API.

You can never be sure that the relationship will hold in the next release, and you also should always invoke Liferay's business logic (in their service tier api) to ensure you get the right object.
Mike Lenox,修改在8 年前。

RE: Service Builder exception using mapping table

New Member 帖子: 10 加入日期: 14-12-30 最近的帖子
Potential workaround: I have a large model with a bunch of many-to-many mappings that always worked fine. I eventually stumbled across this bug when adding a new mapping. I finally noticed that some of my relationships should have triggered the bug, but didn't (lexigraphic order was greater than). At first I couldn't figure out why the old ones worked, but the new ones failed. Turns out that if you have a backwards many-to-many in the target entity, the builder works fine.

For instance, add a fooList attribute to FooBar to correspond to the fooBarList in Foo, both using the same mapping-table..

I suppose that this would only work for 2 custom entities unless you modify LR.
Martin Lojek,修改在7 年前。

RE: Service Builder exception using mapping table

New Member 帖子: 7 加入日期: 10-12-1 最近的帖子
David, thanks for ServiceBuilder investigation. Now I'm struggling with another problem with "mapping-table" issues. Everything worked fine with LR7, beta version 8. Now, when I run blade gw buildService or gradle buildService, even on customized blade-samples, services are generated successfully, but compilation fails.
Methods like method addTableMappings(long,long,long[]), deleteTableMappings(long,long[]) within EntityPersistenceImpl are not resolved.
I would like to set serviceBuilder version manually within build.gradle. Could you let me know, what version is well working one?
thumbnail
David H Nebinger,修改在7 年前。

RE: Service Builder exception using mapping table

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
It's best to go with the latest and greatest as each release addresses issues with the previous.
Martin Lojek,修改在7 年前。

RE: Service Builder exception using mapping table

New Member 帖子: 7 加入日期: 10-12-1 最近的帖子
David, thank's for reply, of course I tested compilation with customized service.xml from "liferay-blade-samples/gradle/blade.servicebuilder.svc" and also created by blade template builder but without success. Attached is customized service.xml, which contains many to many relation of 2 entities (Foo and Doo). Service builder generated code is smoothly compilable with basic entities without many to many relations, but many to many relations causes compilation error.

Service builder runs well, but compilation fails:

Later I tried to modify also build.gradle within blade.servicebuilder.svc to set all dependencies as latest.release, but with no succes.
dependencies {
compile project(':blade.servicebuilder.api')
compile 'biz.aQute.bnd:biz.aQute.bndlib:latest.release'
compile 'com.liferay:com.liferay.osgi.service.tracker.collections:latest.release'
compile 'com.liferay:com.liferay.osgi.util:latest.release'
compile 'com.liferay:com.liferay.portal.spring.extender:latest.release'
compile 'com.liferay.portal:com.liferay.portal.kernel:latest.release'

testCompile 'com.liferay:com.liferay.arquillian.extension.junit.bridge:1.0.0-SNAPSHOT'
testCompile 'junit:junit:4.+'
}


There is compilation error:
symbol: method addTableMappings(long,long,long[])
location: variable dooToFooTableMapper of type TableMapper<Doo,Foo>
/dev/blade-samples/gradle/blade.servicebuilder.svc/src/main/java/com/liferay/blade/samples/servicebuilder/service/persistence/impl/DooPersistenceImpl.java:2948: error: cannot find symbol
dooToFooTableMapper.deleteTableMappings(pk, fooPKs);

Am I missing something?
Martin Lojek,修改在7 年前。

RE: Service Builder exception using mapping table

New Member 帖子: 7 加入日期: 10-12-1 最近的帖子
I resolved that problem for development purpose by changing gradle dependency from compile 'com.liferay.portal:com.liferay.portal.kernel:latest.release' to my local portal-kernel.jar (compile files('{bundle}/tomcat-8.0.32/lib/ext/portal-kernel.jar')), which is latest build from official liferay-portal repository (Liferay Community Edition Portal 7.0.1 GA2 (Wilberforce / Build 7001 / April 29, 2016)).
Now I have no problem to build and compile generated code with many-to-many entities services.
I'm looking forward to see new changes of portal-kernel in official liferay repository https://repository.liferay.com/nexus/content/groups/public/com/liferay/portal/com.liferay.portal.kernel/