So far as I've tested it, these few facelets files with JPA database connections work as intended.  The queue, MyQueue, is at the heart of this small web application.  Each time a user clicks next they're presented with the next bird.  While the app is running, the queue will only send a bird once, to a single user; the queue then progresses to the next bird.  (There might be an offset by one problem, but I'm not concerned about that currently.)My concern, as always, is organization and structure -- idioms.  Am I coming at this the right way?  I just blundered about and found some samples of how others were using EJB's; I just didn't find specific reference information about facelets and JPA -- although there's a great deal of information on the wider world of JSF's.Is there much point to the distinction between QueryBeanWithEntityManager and ClientsQueryBean?  Given the current depth of the application, it seems overkill.  Is there a pay-off for more complex applications?  Or, is there a better way to implement a facade (if that's the appropriate pattern)?See alsoNext bird, next.xhtml:<!DOCTYPE    html  PUBLIC -//W3C//DTD XHTML 1.0  Transitional//EN      http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd><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>    <h:head></h:head>    <h:body>        This and everything before will be ignored        <ui:composition template=template.xhtml>            <ui:define name=navigation>                <ui:include src=menu.xhtml/>            </ui:define>            <ui:define name=main>                <h1>bird</h1>                #{myQueue.next}            </ui:define>        </ui:composition>        This and everything after will be ignored    </h:body></html>MyQueue:package dur.facelets;import dur.database.Clients;import dur.database.ClientsQueryBean;import java.io.Serializable;import java.util.logging.Logger;import javax.ejb.EJB;import javax.inject.Named;import javax.ejb.Singleton;import javax.enterprise.context.ApplicationScoped;//import javax.inject.Singleton;@Named@ApplicationScoped@Singletonpublic class MyQueue implements Serializable {    @EJB    private ClientsQueryBean clientsQueryBean;    private static final long serialVersionUID = 1L;    private final Logger log = Logger.getLogger(MyQueue.class.getName());    private int next = 1001;    public MyQueue() {    }    public int getNext() {        log.info(next\t + next);        Clients c = clientsQueryBean.getClientById(next);        log.info(c.getName());        return next++;    }}ClientsQueryBean:package dur.database;import java.io.Serializable;import java.util.List;import java.util.logging.Logger;import javax.ejb.EJB;import javax.ejb.Stateless;import javax.ejb.LocalBean;@Stateless@LocalBeanpublic class ClientsQueryBean implements Serializable {    private static final long serialVersionUID = 1L;    private final Logger log = Logger.getLogger(ClientsQueryBean.class.getName());    @EJB    private QueryBeanWithEntityManager queryBean;    public List<Clients> getClients() {        return queryBean.getClients();    }    public Clients getClientById(int id) {        return queryBean.getClientById(id);    }}QueryBeanWithEntityManager:package dur.database;import java.util.List;import java.util.logging.Logger;import javax.ejb.LocalBean;import javax.ejb.Stateless;import javax.persistence.EntityManager;import javax.persistence.PersistenceContext;import javax.persistence.Query;import javax.persistence.TypedQuery;@Stateless@LocalBeanpublic class QueryBeanWithEntityManager {    private static final long serialVersionUID = 1L;    private final Logger log = Logger.getLogger(QueryBeanWithEntityManager.class.getName());    @PersistenceContext(name = EnterpriseBirdsJPA-warPU)    EntityManager em;    public QueryBeanWithEntityManager() {    }    public Clients getClientById(int id) {        TypedQuery<Clients> query = em.createQuery(Select e from Clients e where e.id = :id, Clients.class);        query.setParameter(id, id);        Clients c = query.getSingleResult();        return c;    }    public List<Clients> getClients() {        TypedQuery<Clients> query = em.createQuery(select c from Clients c, Clients.class);        List<Clients> result = query.getResultList();        return result;    }}Overall structure:NetBeansProjects/EnterpriseBirds/ build.xml EnterpriseBirds-ejb  build.xml  nbproject   ant-deploy.xml   build-impl.xml   genfiles.properties   private    private.properties    private.xml   project.properties   project.xml  src      conf       MANIFEST.MF      java EnterpriseBirds-war  build.xml  nbproject   ant-deploy.xml   build-impl.xml   genfiles.properties   private    private.properties    private.xml   project.properties   project.xml  setup   sun-resources.xml  src   conf    MANIFEST.MF    persistence.xml   java       dur           database            Clients.java            ClientsQueryBean.java            QueryBeanWithEntityManager.java            reference                AbstractFacade.java                Catalog.java                ClientsFacade.java                Criteria.java           facelets               DirectoryBean.java               Hello.java               MyQueue.java  web      eagle.xhtml      falcon.xhtml      index.xhtml      menu.xhtml      next.xhtml      parrot.xhtml      template.xhtml      WEB-INF          web.xml nbproject  ant-deploy.xml  build-impl.xml  genfiles.properties  private   private.properties   private.xml  project.properties  project.xml src     conf         MANIFEST.MFFor example, can, and should, some classes get moved from EnterpriseBirds-war to EnterpriseBirds-ear?
First facelets with JPA app on glassfish
java;design patterns;jpa;jsf
Based on your current project structure, I suggest the following changes, these changes follow the most common structure found between JSF developers, which is the minimum:Rename QueryBeanWithEntityManager to QueryDAO and keep injecting EntityManager and etc, the purpose here is make clear the purpose of this class as data access object with persistence logic of application, if you need some business logic I recommend start using Service Layer patter and inject QueryDAO there.Normalize bean names to be ClientsQueryBean and MyQueueBeanIn fact there's a lot if distinction between ClientsQueryBean and QueryBeanWithEntityManager, the first only should only act as view controller to perform validation, handle user actions and feed the views view EL bindings, the second should always handle only database related tasks, like query data, update and delete via JPA.Some people also creates interfaces for DAOs, so the user may have JPA based implementations, Spring JDBC Template and iBatis implementations too.