I have a table of NewsFeed
.
NewsFeed
+ id
+ fromUserId
+ targetId
+ type
so the news is like this: Tom Wakefield
commented on Peter Smith
's profile.
So either I add two more fields into my NewsFeed
call fromUserName
and targetUserName
OR
For every row I display in my dataTable I would query from the Entity
.
<p:dataTable value="#{myBean.news}" var="item">
<p:column>
<h:outputText value="#{myBean.getName(item.fromUserId)} " />
<h:outputText value="commented on " />
<h:outputText value="#{myBean.getName(item.targetId)}" />
</p:column>
</p:dataTable>
then inside myBean.java
myBean.java
public String getName(Long userId){
User u = mySessionBean.findUserById(userId);
return u.getFName() + " " + u.getLName();
}
Which way is better? Does making query at every row really hurting me a lot in term of performance
Note: the database expect to have lot of users. News
are display very often.