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?

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top