How can we get liferay objects through custom search using custom SQL?
Below is my sql query written in default.xml ( ). I trimmed the request to the minimum minimum so that the logic remains simple. Since it includes several functions and associations, we could not use the DynamicQuery API ):
SELECT grp.* FROM Group_ WHERE site = 1 AND active_ = 1 AND type_ <> 3
Relevant code in MyCustomGroupFinderImpl.java :
Session session = null; try { session = openSession();
This code above will not work, since the GroupImpl class GroupImpl present in portal-impl.jar , and this jar cannot be used in the user portlet.
I also tried using sqlQuery.addEntity("Group_", PortalClassLoaderUtil.getClassLoader().loadClass("com.liferay.portal.model.impl.GroupImpl"))
But this code above raises an exception:
com.liferay.portal.kernel.exception.SystemException: com.liferay.portal.kernel.dao.orm.ORMException: org.hibernate.MappingException: Unknown entity: com.liferay.portal.model.impl.GroupImpl
But the same code works for our custom object if we write sqlQuery.addEntity("MyCustomGroup", MyCustomGroupImpl.class); .
thanks
Prakash k
source share