5

I have two plugin portlets. First has service builder with all entities. Second portlet is using service's jar file to execute Dynamic query.

I am using first's service jar in my second plugin portlet to interact with database. But in this jar file there is not any Impl class. Thats why i am getting error Impl Class not found. Below is for 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] Unable find model com.compass.model.impl.XXXImpl java.lang.ClassNotFoundException: com.compass.model.impl.XXXImpl

Nomal Functions are working fine of service builder

Varun Arya
  • 335
  • 1
  • 14

3 Answers3

6

just don't use the DynamicQueryFactoryUtil but the 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 the factory you have to use the interface model not the impl of the entity so if you have an entity FooImpl sue the Foo.class and use the classloder of you service plugin portlet

Classloader cl =(ClassLoader) PortletBeanLocatorUtil.locate("services-portlet", "portletClassLoader");
DynamicQueryFactoryUtil.forClass(XXX.class, cl);
Romeo Sheshi
  • 901
  • 5
  • 7
  • Hi @romeo, In my XXX-service.jar there is not any XXXImpl class. That's why i am getting the error. – Varun Arya Mar 28 '17 at 12:04
  • By your example it is giving 'java.lang.RuntimeException: java.lang.ClassNotFoundException is not a valid exception' error. – Varun Arya Mar 28 '17 at 12:05
  • you don't need the impl class just the interface of that class. you don't have access to impl the services work this way – Romeo Sheshi Mar 28 '17 at 12:05
  • I have added first's XXX-service.jar in lib folder and also tried with adding it into tomcat lib/ext folder. But while getting the data with dynamic query. it is giving error '[DynamicQueryFactoryImpl:96] Unable find model com.compass.model.impl.XXXImpl'. – Varun Arya Mar 28 '17 at 12:15
  • sorry i've misunderstand the problem you have to user the service-portlet classloader and not the portalclassloader. the portalclassloader is for liferay entities. i've update the answer. But if you use the method XXXLocalServiceUtil.dynamicQuery() to get the dynamic query you will not have problem like this. – Romeo Sheshi Mar 28 '17 at 12:27
1

Both works 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.

Varun Arya
  • 335
  • 1
  • 14
0
public static void getuserList(){
        DynamicQuery dynamicQuery = XXLocalServiceUtil.dynamicQuery();
        System.out.println("dynamicQuery");
        dynamicQuery.add(PropertyFactoryUtil.forName("field1").eq("field_name"));
        List<XX> userList = XXLocalServiceUtil.dynamicQuery(dynamicQuery);
        System.out.println(userList);
}

This is working for me !!!!