Error while extracting ddmStructures from DDMStructureLocalServiceUtil

thumbnail
Shiva Lingam K, modified 6 Years ago. New Member Posts: 18 Join Date: 5/9/18 Recent Posts
Hello everyone,
I am trying to get all ddmStructures from DDMStructureLocalServiceUtil in Liferay 7.2 as follows

List<DDMStructure> ddmStructures = 
DDMStructureLocalServiceUtil.getClassStructures(companyId, PortalUtil.getClassNameId(DLFileEntry.class), new StructureStructureKeyComparator(true));

​​​​​​​
​​​​​​​But I am getting below exceptionStacktrace of Exception:-
java.lang.ClassCastException: com.sun.proxy.$Proxy1676 cannot be cast to com.liferay.dynamic.data.mapping.service.DDMStructureLocalService
at com.liferay.dynamic.data.mapping.service.DDMStructureLocalServiceUtil.getService(DDMStructureLocalServiceUtil.java:1285)
at com.liferay.dynamic.data.mapping.service.DDMStructureLocalServiceUtil.getClassStructures(DDMStructureLocalServiceUtil.java:620)

Build.gradle:-
dependencies {
   compileOnly group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.5.0"
   compileOnly group: "com.liferay", name: "com.liferay.portal.configuration.metatype", version: "2.0.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "4.0.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.0.0"
compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
compileOnly group: "jstl", name: "jstl", version: "1.2"
compileOnly group: "org.osgi", name: "osgi.cmpn", version: "6.0.0"
compileInclude group: 'com.liferay', name: 'com.liferay.dynamic.data.mapping.api', version: '3.9.0'}
Can anyone please help me to resolve this issue. 
thumbnail
Russell Bohl, modified 6 Years ago. Expert Posts: 308 Join Date: 2/13/13 Recent Posts
Is that at compile time? If you're not getting a compile time error it's probably not a problem with your dependency management. I believe you'll be best served by getting and calling the injected service rather than using the static service util. In the Declarative Services world of Liferay 7.2 it's done using an @Reference annotation:
@Reference
private DDMStructureLocalService _ddmStructureLocalService;
However, looking at your dependencies, I think it's strange that you're depending on version 3.9.0 of the DDM API. I was just looking at another post regarding the DDM API on 7.2, and the version is 5.2.0. So those are a couple of things worth looking into.