Retrieving Blogs Comments

If you need to retrieve all comments that have been made to blogsentries (com.liferay.portlet.blogs.model.BlogsEntry), you need to know that Liferay stores all comments as message board messages. So you need to do the following to get all comments:

table: mbMessage


classNameId: ClassNameId of BlogsEntry
parentMessageId: Not 0
classPK: Primary Key of your BlogsEntry
categoryId: must be -1

DynamicQuery mbMessageQuery = DynamicQueryFactoryUtil.forClass(MBMessage.class, PortalClassLoaderUtil.getClassLoader());

long blogsEntryClassNameId = ClassNameLocalServiceUtil.getClassNameId(BlogsEntry.class.getName());
mbMessageQuery.add(RestrictionsFactoryUtil.eq("classNameId", blogsEntryClassNameId));
List dynamicQuery = MBMessageLocalServiceUtil.dynamicQuery(mbMessageQuery);

If you like this post it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.