留言板

self referencing Entity in liferay service builder

Alireza Goli,修改在6 年前。

self referencing Entity in liferay service builder

New Member 帖子: 10 加入日期: 17-7-24 最近的帖子
Hi,
Is there any way to create self referencing entity in liferay service builder? something like:

public class comment{
public List<comment> answers;
}

thanks,
Alireza
thumbnail
Christoph Rabel,修改在6 年前。

RE: self referencing Entity in liferay service builder

Liferay Legend 帖子: 1554 加入日期: 09-9-24 最近的帖子
I am guessing here that you want to have "childcomments".

You could add a long parentCommentId to the entity in the service.xml. With that parentId you could create a tree of comments. Then add a finder for parentId.

Then you could add a method to the CommentModelImpl class.

public List<comment> getSubComments() {
return persistenceSomething.findByParentId(this.commentId);
}

Note: I am not sure if the comment persistence interface is available in the ModelImpl class. You might need to add a getSubComments(long commentId) in the CommentLocalServiceImpl and call that one instead.
Alireza Goli,修改在6 年前。

RE: self referencing Entity in liferay service builder

New Member 帖子: 10 加入日期: 17-7-24 最近的帖子
Thanks