Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Christian Schulze
How get List of latest Article with DynamicQuery
June 12, 2012 5:44 AM
Answer

Christian Schulze

Rank: Junior Member

Posts: 87

Join Date: November 19, 2009

Recent Posts

Hello,
I want to get a List of latest JournalArticle for a given List of articleIds. I mean that I want to get the latest JournalArticle with the highest version. But for n JournalArticle with one query.

I try this

1
2        final Object[] array = articleIds.toArray();
3        final DynamicQuery query = DynamicQueryFactoryUtil.forClass(JournalArticle.class, PortalClassLoaderUtil.getClassLoader());
4        query.add(PropertyFactoryUtil.forName("articleId").in(array));
5        query.setProjection(ProjectionFactoryUtil.max("version"));
6
7        final List<JournalArticle> dynamicQuery = JournalArticleLocalServiceUtil.dynamicQuery(query);


But get an Exception that Double can't be cast to JournalArticle. But how can I build a DynamicQuery to get a List of JournalArticle by max version?

regards Chris
Apoorva Prakash
RE: How get List of latest Article with DynamicQuery
June 13, 2012 11:02 AM
Answer

Apoorva Prakash

Rank: Liferay Master

Posts: 659

Join Date: June 15, 2010

Recent Posts

Hi Christian,

Can't say much about dynamic query, but the second function in this link works the same...

Hope this will help...

Thanks and Regards,
Apoorva Prakash
Gwowen Fu
RE: How get List of latest Article with DynamicQuery
October 4, 2012 2:21 PM
Answer

Gwowen Fu

Rank: Expert

Posts: 253

Join Date: December 27, 2010

Recent Posts

Christian Schulze:

But get an Exception that Double can't be cast to JournalArticle. But how can I build a DynamicQuery to get a List of JournalArticle by max version?


It is because the projection and it only returns data from "version" column.

Regards,
Gwowen