How to get one instance of list using select statement in EJB 3 and JSF
Now i'm working with EJB 3 in Stateless Bean i create method get all instance of entity About
public List<About> retrieveAllAbout(){
return em.createNameQuery("About.findAll").getResultList();
}
Now i want get 开发者_Go百科one row of list to pass to js page. How can i do it
in jsf page ( xhtml) i want show one value of list example
<h:outputText value="#{bean.value}" />
(in database i have one row only one row i want select, otherway if i have many row how can i select and get one row and show it to JSF page)
Try using getSingleResult method and get your "retrieveAllAbout" method to return "About" object instead of List. In case there are more rows in database and you are trying to get the first one use getFirstResult. Otherwise you would have to be more specific when defining the query.
javax.persistence.Query
精彩评论