Liferay Serivce Builder: Cannot Run Dynamic Query

I have two plugin portlets. First, a service builder is created with all the objects. The second portlet uses the service jar file to make a dynamic request.

I am using the first service jar in the second plugin portlet to interact with the database. But there is no Impl class in this jar file. This is why I am getting the error. The Impl class was not found. The following is for your reference:

DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(XXX.class,
PortletClassLoaderUtil.getClassLoader());
try {
    XXXLocalServiceUtil.dynamicQuery(dynamicQuery);
} catch (SystemException e1) {
  // TODO Auto-generated catch block
  e1.printStackTrace();
}

      

Error: [DynamicQueryFactoryImpl: 96] Cannot find model com.compass.model.impl.XXXImpl java.lang.ClassNotFoundException: com.compass.model.impl.XXXImpl

The nominal functions work fine in the service builder

+3


source to share


2 answers


just don't use DynamicQueryFactoryUtil but XXXLocalServiceUtil this way

DynamicQuery dynamicQuery = XXXLocalServiceUtil.dynamicQuery() 
try {
    XXXLocalServiceUtil.dynamicQuery(dynamicQuery);
} catch (SystemException e1) {
  // TODO Auto-generated catch block
  e1.printStackTrace();
}

      



If you want to use a factory, you need to use the interface model, not the entity entity, so if you have the entity FooImpl, file a claim in Foo.class and use the classloder of your service plugin portlet

Classloader cl =(ClassLoader) PortletBeanLocatorUtil.locate("services-portlet", "portletClassLoader");
DynamicQueryFactoryUtil.forClass(XXX.class, cl);

      

+4


source


Both work for me ..

ClassLoader classLoader = (ClassLoader)PortletBeanLocatorUtil.locate(ClpSerializer.getServletContextName(), "portletClassLoader");

OR



ClassLoader classLoader = PortletBeanLocatorUtil.getBeanLocator(ClpSerializer.getServletContextName()).getClassLoader();

DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(charges.class,classLoader);

Thanks @Romeo.

+1


source







All Articles