开发者

How to get one instance of list using select statement in EJB 3 and JSF

开发者 https://www.devze.com 2023-01-18 09:35 出处:网络
Now i\'m working with EJB 3 in Stateless Bean i create method get all instance of entity About public List<About> retrieveAllAbout(){

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

0

精彩评论

暂无评论...
验证码 换一张
取 消