Liferays Service Builder - 多对多关系
我正在尝试在我自己的实体和 liferay Group 实体之间创建一个多对多
。我的 service.xml 看起来像这样
<entity name="EntityA" local-service="true" remote-service="false">
<column name="entityAId" type="long" primary="true" />
<column name="title" type="String" />
<column name="summary" type="String" />
<column name="authorId" type="long" />
<column name="attachments" type="Collection" entity="EntityAAttachment" mapping-key="entityAId" />
<column name="groups" type="Collection" entity="com.liferay.portal.Group" mapping-table="EntityAs_Groups" />
</entity>
根据 service.xml 的 DTD,这应该生成多对多关系,但我只得到这个
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@21ff3fcf
The problematic instruction:
----------
==> list serviceBuilder.getMappingEntities(column.mappingTable) as mapColumn [on line 201, column 49 in com/liferay/portal/tools/servicebuilder/dependencies/model_impl.ftl]
----------
Java backtrace for programmers:
----------
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@21ff3fcf
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Environment.visit(Environment.java:299)
at freemarker.core.CompressedBlock.accept(CompressedBlock.java:73)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.IfBlock.accept(IfBlock.java:82)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
at freemarker.core.Environment.visit(Environment.java:417)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Environment.process(Environment.java:190)
at freemarker.template.Template.process(Template.java:237)
at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:49)
at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:39)
at com.liferay.portal.tools.servicebuilder.ServiceBuilder._processTemplate(ServiceBuilder.java:4447)
at com.liferay.portal.tools.servicebuilder.ServiceBuilder._createModelImpl(ServiceBuilder.java:2420)
at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:1023)
at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:404)
at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:176)
Caused by: java.lang.NullPointerException
at com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(ServiceBuilder.java:1366)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:840)
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
... 32 more
我在这里做错了什么?我正在使用最新的 Liferay stable 6.0.5
I'm trying to create a many-to-many
between my own entity and the liferay Group entity. My service.xml looks like this
<entity name="EntityA" local-service="true" remote-service="false">
<column name="entityAId" type="long" primary="true" />
<column name="title" type="String" />
<column name="summary" type="String" />
<column name="authorId" type="long" />
<column name="attachments" type="Collection" entity="EntityAAttachment" mapping-key="entityAId" />
<column name="groups" type="Collection" entity="com.liferay.portal.Group" mapping-table="EntityAs_Groups" />
</entity>
According to the DTD of the service.xml this should generate a many-to-many relation but I only get this
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@21ff3fcf
The problematic instruction:
----------
==> list serviceBuilder.getMappingEntities(column.mappingTable) as mapColumn [on line 201, column 49 in com/liferay/portal/tools/servicebuilder/dependencies/model_impl.ftl]
----------
Java backtrace for programmers:
----------
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@21ff3fcf
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Environment.visit(Environment.java:299)
at freemarker.core.CompressedBlock.accept(CompressedBlock.java:73)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.IfBlock.accept(IfBlock.java:82)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)
at freemarker.core.Environment.visit(Environment.java:417)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:210)
at freemarker.core.Environment.process(Environment.java:190)
at freemarker.template.Template.process(Template.java:237)
at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:49)
at com.liferay.portal.freemarker.FreeMarkerUtil.process(FreeMarkerUtil.java:39)
at com.liferay.portal.tools.servicebuilder.ServiceBuilder._processTemplate(ServiceBuilder.java:4447)
at com.liferay.portal.tools.servicebuilder.ServiceBuilder._createModelImpl(ServiceBuilder.java:2420)
at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:1023)
at com.liferay.portal.tools.servicebuilder.ServiceBuilder.<init>(ServiceBuilder.java:404)
at com.liferay.portal.tools.servicebuilder.ServiceBuilder.main(ServiceBuilder.java:176)
Caused by: java.lang.NullPointerException
at com.liferay.portal.tools.servicebuilder.ServiceBuilder.getMappingEntities(ServiceBuilder.java:1366)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:840)
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
... 32 more
What I'm doing wrong here? I'm using the latest Liferay stable 6.0.5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是 Liferay 中未解决的错误:https://issues.liferay.com/browse/LPS-49769
更改实体的字典顺序可能会解决此问题,但会解决生成的源代码不正确的问题。
Mike Lenox 的潜在解决方法 https://www.liferay.com/community /forums/-/message_boards/message/41347203:
另一种解决方法是将映射自己定义为实体,如 http://blog.d-vel.com/home/-/blogs/service-builder-e-relazioni-many-to-many(意大利语):
This is an unresolved bug in Liferay: https://issues.liferay.com/browse/LPS-49769
Changing the lexicographical order of your entities might solve this problem but resolve in incorrect generated source code.
Potential workaround by Mike Lenox at https://www.liferay.com/community/forums/-/message_boards/message/41347203 :
Another workaround is to define the mapping yourself as an entity, as suggested by http://blog.d-vel.com/home/-/blogs/service-builder-e-relazioni-many-to-many (in Italian):
我很确定您无法在实体和门户实体之间建立一对多或多对多的关系。至少不直接使用Service Builder。请考虑您的 portlet 和门户是独立的上下文。
正如其他答案中所建议的,不。永远不要弄乱portal-impl.jar。这是非常不鼓励的。
我建议模拟这种关系,在 EntityAServiceImpl 和 EntityALocalServiceImpl 类中实现所需的方法。我认为这将是最干净的方式。
看看这个..
https: //dev.liferay.com/develop/tutorials/-/knowledge_base/6-2/writing-local-service-classes
希望有帮助
I am pretty sure you can not make one-to-many nor many-to-many relationship between your entities and portal entities. At least not directly using the Service Builder. Take into account that your portlet and the portal are separate contexts.
And as suggested in other answer, NO. NEVER mess with the portal-impl.jar. It is highly discouraged.
I would suggest to simulate this relationship implementing the required methods in EntityAServiceImpl and EntityALocalServiceImpl classes. I think this will be the cleanest way to go.
Have a look at this..
https://dev.liferay.com/develop/tutorials/-/knowledge_base/6-2/writing-local-service-classes
Hope that helps
Lferay 组实体、服务和实现位于 ROOT/web-inf/lib 下的 Portal-impl.jar 中,因此,如果您尝试使用该实体,它们的实现和服务超出了范围,那么您有两种选择:您将portal-impl 移动到运行时的全局类路径(这是一个错误的选择,因为您还必须移动所有其他库),或者将portal-impl 移动到您的portlet 类路径(这也是一个错误的选择)。 。
最好的解决方案是使用
hook
,以便可以访问portal-impl。然后将service-builder生成的lib移动到服务器tomcat/lib/ext的全局类路径,这样它将位于你的 portlet.it 的范围对我来说效果很好。在包含实体之前添加引用
Lferay group entity,service and implementations are in portal-impl.jar which is under ROOT/web-inf/lib, so if you are trying to use that entity their implementation and service are out of scope, then you have two choices, either you move portal-impl to the global classpath of your runtime (which a bad choice cause you'll have to move all the other libs too) or you move portal-impl to your portlet class path (which is a bad choice too)..
The best solution is to use a
hook
so portal-impl will be reachable..then move the lib that service-builder generates to global class path of your server tomcat/lib/ext so it will be in the scope of your portlet.it works fine for me.Add a reference before enclosing your entity
有关 Liferay Servie 构建器的更多信息请查看这篇文章。
http://liferaydemystified.blogspot.com/2011/04 /mvc-portlet-development-service-builder.html
for more on Liferay Servie builder Check out this post .
http://liferaydemystified.blogspot.com/2011/04/mvc-portlet-development-service-builder.html