Liferay 7.2- Alternative to ClpSerializer

Fabio Carvalho, modified 6 Years ago. Junior Member Posts: 81 Join Date: 6/25/19 Recent Posts
I have created a service builder module and I have also successfully integrated with my portlet module.

Now I am trying to execute a DynamicQuery and I am getting an ClassNofFoundException error. He cant found my packagename.model.impl.EntityImpl.

I am doing my query like this:
DynamicQuery query = DynamicQueryFactoryUtil.forClass(Entity.class, Entity.class.getClassLoader());
query.add(PropertyFactoryUtil.forName("userId").eq((int) theme.getLayout().getUserId()));
​​​​​​​
List<Entity> entities = EntityLocalServiceUtil.dynamicQuery(query);

I have seen that this should be a classLoader problem and the solution should be using the ClpSerializer class:
ClassLoader classLoader = (ClassLoader) PortletBeanLocatorUtil.locate(ClpSerializer.SERVLET_CONTEXT_NAME, "portletClassLoader");

But my service builder didn't generate this class. If I understand correctly, it doesn't generated anymore. So, is there any alternative to the ClpSerializer? How should I use the classLoader to execute the query correctly?
thumbnail
Mohammed yasin, modified 6 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Hi,
Try using this
DynamicQuery query = EntityLocalServiceUtil.dynamicQuery();
query.add(PropertyFactoryUtil.forName("userId").eq((int) theme.getLayout().getUserId()));
List<Entity> entities = EntityLocalServiceUtil.dynamicQuery(query);
Fabio Carvalho, modified 6 Years ago. Junior Member Posts: 81 Join Date: 6/25/19 Recent Posts
Hi Mohammed,

Your way is working perfectly. Thank you very much!