Search code examples
javaliferayentityliferay-service-builder

One to Many relationship in Liferay Service Builder


I've started learning Liferay (6.2) about a week ago for a project. I've used "pure" Java EE before (JSP, JSF, etc.) with JPA (EclipseLink).

What I can't understand is:

How to use ServiceBuilder to create entities that behave like the ones I defined before For e.g.: if I define a Category and a CategoryProperty entity, which are in a one-to-many relationship, I can only define a finder to the CategoryProperty which returns all the CategoryPropertys by the parent categoryId.

Based on the book I'm reading, I can only modify the implementation of the CategoryLocalServiceImpl and the CategoryPropertyLocalServiceImpl and can't touch the generated entities. So if I want to list every CategoryProperty which belongs to one Category, I have to implement and call CategoryPropertyLocalServiceUtil.findAllByCategoryId(categoryId) which is not what i want. The category.getCategoryProperties() call would be much more natural.

How do I achieve that without messing up the whole structure? Which generated classes can I touch? what is that I am missing?

Thank you!


Solution

  • Shortly, what you understand is right but it's not the whole story.

    You can catch what you want implementing method getCategoryProperties() in CategoryImpl class.

    That method will use the finder method you previously made and describe in the question.