title: JSF 2 Lifecycle
body: <p>I have this code for BookModel.java:</p>
  
  <pre><code>@Entity
  @Table(name = "BOOK")
  @NamedNativeQuery(name = "BookModel.findBookTitle", query = "SELECT @rownum:=@rownum+1 'no', m.title, m.author, REPLACE(SUBSTRING_INDEX(m.content, ' ', 30), '&lt;br&gt;', ' '), m.viewed, m.hashid FROM book m, (SELECT @rownum:=0) r WHERE m.title like 'a%'")
  public class BookModel implements Serializable
  {
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MY_SEQ_GEN")
      @Column(name = "id", unique = true, nullable = false)
      private Long id;
  
      @NotNull
      @Size(min = 1, max = 255)
      @Column(name = "title")
      private String title;
  
      @NotNull
      @Size(min = 1, max = 255)
      @Column(name = "author")
      private String author;
  }   
  </code></pre>
  
  <p>And BookService.java for the business layer:</p>
  
  <pre><code>@Stateless
  public class BookService
  {
      @SuppressWarnings("unchecked")
      public List&lt;BookModel&gt; getBook() {
         Query query = entityManager.createNamedQuery("BookModel.findBookTitle");
         List&lt;BookModel&gt; result = query.getResultList();
         return result;
      }
   }
  </code></pre>
  
  <p>And BookBean.java for the presentation layer:</p>
  
  <pre><code>@ManagedBean(name = "BookBean")
  @RequestScoped
  public class BookBean implements Serializable
  {
      @EJB
      private BookService bookService;
      private DataModel&lt;BookModel&gt; book;
  
      public DataModel&lt;BookModel&gt; getBook() {
         return book;
      }
  }   
  </code></pre>
  
  <p>And the page book.xhtml:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"&gt;
      &lt;p:dataTable id="bookList" value="#{BookBean.book}" var="book"&gt;
      ...
      &lt;/p:dataTable&gt; 
   &lt;/html&gt;
  </code></pre>
  
  <p>My question is: How can I restrict the method <strong>getBook()</strong> in <strong>BookBean</strong> to be executed only once instead of six times - presumably for each phase of JSF lifecycle. Has anyone else come across this before? Please help. Have been stuck on this for the last day without any success.</p>