RE: Dependency issue for JournalArticle Impl in Liferay 7.1

deveshree zawar, modified 7 Years ago. Junior Member Posts: 61 Join Date: 2/9/16 Recent Posts

Hi,

I am accessing the journal article impl class for the custom sql i have created.

Below is my piece of code:

SQLQuery query = session.createSQLQuery(sql);
        query.setCacheable(false);
        query.addEntity("JournalArticle", PortalClassLoaderUtil.getClassLoader().loadClass("com.liferay.journal.model.impl.JournalArticleImpl"));

I have below dependencies in build.gradle:

compileOnly group: 'com.liferay', name: 'com.liferay.journal.service', version: '2.0.2'  
    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.impl", version: "2.32.0"
    compileOnly group: "com.liferay", name: "com.liferay.journal.api", version: "2.0.0"
    compileOnly group: "com.liferay", name: "com.liferay.journal.web", version: "1.5.0"

 

But i am getting the below error : 

Unresolved requirement: Import-Package: com.liferay.journal.model.impl; version="[1.0.0,2.0.0)"

java.lang.ClassNotFoundException: com.liferay.journal.model.impl.JournalArticleImpl

 

Not finding any relevant dependency to be added in build.gradle.

Any help would be appreciated.

thumbnail
David H Nebinger, modified 7 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts

JournalArticleImpl is not in the portal's class loader.  With using PortalClassLoaderUtil.getClassLoader(), you are asking for the portal's class loader which will not have the JournalArticleImpl class in it.

I'm not sure what you're doing, but you may find it a bit easier to just use a dynamic query.

deveshree zawar, modified 7 Years ago. Junior Member Posts: 61 Join Date: 2/9/16 Recent Posts

Hi david,

I am trying to get result from multiple table with inner join. So created custom sql for the journal article table.

<custom-sql>
    <sql id = "com.acc.bby.service.persistence.ConfigurationFinder.findJournalArticleByCategoryIds">
    SELECT * FROM journalarticle ja 
    INNER JOIN assetentry ae ON ae.classPK = ja.resourcePrimKey
    INNER JOIN assetentryassetcategoryrel ae_at ON ae.entryId = ae_at.assetEntryId
    INNER JOIN assetcategory tags ON ae_at.assetCategoryId = tags.categoryId 
    WHERE tags.categoryId IN (?) AND  ja.status = (?);
    </sql>
</custom-sql>

Attached is my FinderImpl class.

I am facing issue on adding the entity :

query.addEntity("JournalArticle", JournalArticleImpl.class));

I have tried accessing the JournalArticleImpl class using the class loader as well as the above line, but m facing the dependency issues.

thumbnail
David H Nebinger, modified 7 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts

I'm not sure there's a workable solution for this.

The different entities are parts of different class loaders.  You may not be able to cross these boundaries so easily.

thumbnail
Amos Fong, modified 7 Years ago. Liferay Legend Posts: 2047 Join Date: 10/7/08 Recent Posts

You could select the journalArticle.resourcePrimKey instead and then retrieve the journalArticles yourself via the journalArticleLocalService