Question

Since when edit a web content, liferay automatically creates new version of an article, I want to get the latest version of a specific article. I used the dynamic query as follows:

DynamicQuery query = DynamicQueryFactoryUtil.forClass(JournalArticle.class, PortletClassLoaderUtil.getClassLoader());

query.setProjection(ProjectionFactoryUtil.max("version")); 
List<JournalArticle> jList = (List<JournalArticle>)JournalArticleLocalServiceUtil.dynamicQuery(query);

I searched on google and notice ProjectionFactoryUtil.max("version") was used a lot. But in my case, exceptions have thrown:

"java.lang.Double cannot be cast to com.liferay.portlet.journal.model.JournalArticle"

Am I missing something?

Was it helpful?

Solution

Use of ProjectionFactoryUtil.max("version") in DynamicQuery will return double value which will be maximum of field 'version'. You are trying to cast double type value to JournalArticle thats why facing this exception.

HTH Sent from mobile.

OTHER TIPS

As for the intent of getting the latest version of a JournalArticle: JournalArticleLocalServiceUtil has an API method fetchLatestArticle (with a few varying parameter sets, for example to prefer published articles over non-published). In Liferay 5.x it's called getLatestArticle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top