We already know how to write dynamic query in Liferay. If we create Dynamic Query object in same portlet in which our service are then we can use :-
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DynamicQuery query = DynamicQueryFactoryUtil.forClass(Employee.class, "emp",PortletClassLoaderUtil.getClassLoader()); | |
But if we use this code in another portlet ie Services in one portlet and our portlet is different then we get error on our console:-
[DynamicQueryFactoryImpl:96] Unable find model com.liferay.sample.model.impl.EmployeeImpl
java.lang.ClassNotFoundException: com.liferay.sample.model.impl.EmployeeImpl
Solution:-
In this case you can create Dynamic Query Object as:-
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ClassLoader classLoader = (ClassLoader)PortletBeanLocatorUtil.locate(ClpSerializer.getServletContextName(),"portletClassLoader"); | |
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Employee.class, "emp", classLoader); | |
Explanation:-
The only difference is the way how we use the Class Loader.
The only difference is the way how we use the Class Loader.
Hope this will Help....
Related Post:-
No comments:
Post a Comment