4

在我的 6.1.0 门户实例上,使用 ServiceBuilder 和 DL-Api 的 6.1.0 SDK-Portlet 这行:

DynamicQuery query = DynamicQueryFactoryUtil.forClass(DLFileEntry.class)

产生此错误:

16:46:46,319 ERROR [DynamicQueryFactoryImpl:83] Unable find model 
com.liferay.portlet.documentlibrary.model.impl.DLFileEntryImpl
java.lang.ClassNotFoundException: com.liferay.portlet.documentlibrary.model.impl.DLFileEntryImpl
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)
    at com.liferay.portal.dao.orm.hibernate.DynamicQueryFactoryImpl.getImplClass(DynamicQueryFactoryImpl.java:78)
    at com.liferay.portal.dao.orm.hibernate.DynamicQueryFactoryImpl.getImplClass(DynamicQueryFactoryImpl.java:59)
    at com.liferay.portal.dao.orm.hibernate.DynamicQueryFactoryImpl.forClass(DynamicQueryFactoryImpl.java:33)
    at com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil.forClass(DynamicQueryFactoryUtil.java:23)
    at de.acocon.liferay.service.service.bean.DocLibBean.findByExtraSettings(DocLibBean.java:403)
    at de.acocon.liferay.service.service.bean.DocLibBean.findByIdeaId(DocLibBean.java:395)
    at de.acocon.liferay.service.service.bean.DocLibBean.fillUploadedFileListByIdea(DocLibBean.java:417)
    at de.acocon.liferay.service.service.bean.IdeaController.init(IdeaController.java:149)
    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 com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:117)
    at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:99)
    at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:223)
    at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:105)
    at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
    at org.jboss.el.parser.AstValue.getValue(AstValue.java:63)
    at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
    at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:224)
    at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
    at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
    at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
    at org.icefaces.impl.context.DOMPartialViewContext.processPartial(DOMPartialViewContext.java:153)
    at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
    at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
    at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:981)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:390)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at com.liferay.faces.bridge.lifecycle.LifecycleWrapper.render(LifecycleWrapper.java:45)
    at com.liferay.faces.bridge.BridgePhaseResourceImpl.execute(BridgePhaseResourceImpl.java:115)
    at com.liferay.faces.bridge.BridgeImpl.doFacesRequest(BridgeImpl.java:115)
    at javax.portlet.faces.GenericFacesPortlet.serveResource(GenericFacesPortlet.java:178)
    at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:118)
    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71)
    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:93)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
    at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:634)
    at com.liferay.portlet.InvokerPortletImpl.invokeResource(InvokerPortletImpl.java:746)
    at com.liferay.portlet.InvokerPortletImpl.serveResource(InvokerPortletImpl.java:503)
    at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:941)
    at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:664)
    at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:244)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
    at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:174)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:533)
    at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:510)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:113)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:113)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:113)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
    at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:201)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
    at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:240)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
    at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:135)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:113)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:113)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
    at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:123)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
    at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:201)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
    at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:241)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
    at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:240)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
    at com.liferay.portal.servlet.filters.sso.ntlm.NtlmPostFilter.processFilter(NtlmPostFilter.java:83)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
    at com.liferay.portal.sharepoint.SharepointFilter.processFilter(SharepointFilter.java:80)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
    at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)
    at com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.processFilter(VirtualHostFilter.java:208)
    at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:48)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:184)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:203)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:105)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:164)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:164)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:184)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:92)
    at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:70)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)

我搜索了几个小时的原因,但我没有找到它。我还尝试将 portal-impl.jar 添加到我的 lib/ 文件夹中,但这没有帮助而且不好;)

请说我应该使用新版本,因为我无法更改 -> 客户为王

谢谢你的帮助!

4

3 回答 3

10

这似乎是一个类加载器问题,在 liferay 中有不同的类加载器,如(粗略解释):

  1. 插件类加载器:从“/my-portlet/WEB-INF/lib/”加载插件类
  2. 门户类加载器:从portal-impl.jar
  3. 全局类加载器:加载服务器类,即来自的类../tomcat-7.0.27/lib/ext/

所以有不同的方法可以将类DynamicQuery从一个类加载器加载到另一个类中。

以下是您可以DynamicQuery根据实现类所在位置使用的方式:

  1. 如果实现类在您的自定义 portlet 中,那么: 不要使用特殊的类加载器 - 它应该可以开箱即用。

  2. 如果 Implementation 类是门户的一部分(即来自portal-impl.jarlike UserRoleGroup在您的情况下DLFileEntry),则使用以下内容:

    Classloader loader = PortalClassLoaderUtil.getClassLoader();
    DynamicQuery query = DynamicQueryFactoryUtil.forClass(DLFileEntry.class, loader);
    
  3. 如果实现类在另一个 portlet 中,则使用以下内容:

    ClassLoader classLoader = (ClassLoader) PortletBeanLocatorUtil.locate(ClpSerializer.SERVLET_CONTEXT_NAME,"portletClassLoader");
    DynamicQuery query = DynamicQueryFactoryUtil.forClass(DLFileEntry.class, classLoader);
    

所以回答你的问题:第二种方法应该适合你。

信息转载自Liferay 论坛帖子

于 2013-01-21T09:44:20.023 回答
0

试试下面的代码:

DynamicQuery query = DynamicQueryFactoryUtil.forClass(DLFileEntry.class, DLFileEntry.class.getClassLoader());

对我来说,它奏效了。

于 2015-11-30T11:26:07.180 回答
0

就我而言,我们使用的是自定义表。每当我尝试从我的 EntityServiceImpl 类中获取数据时,我都会遇到同样的错误。其中 Entity 是我的表的名称。在这里,我们公开了我们的 liferay 服务。使用代码解决的问题

ClassLoader classLoader = (ClassLoader) PortletBeanLocatorUtil.locate(ClpSerializer.getServletContextName(),"portletClassLoader");
DynamicQuery query = DynamicQueryFactoryUtil.forClass(Entity.class, classLoader);

但是请使用 ClpSerializer.getServletContextName() 而不是 ClpSerializer.SERVLET_CONTEXT_NAME。正如kgiannakakis所说。

于 2016-06-01T04:25:12.187 回答