8 Replies Latest reply on Sep 8, 2008 11:37 AM by David Beaumont

    Query repeated over and over

    David Beaumont Newbie


      I have a contact class which is backed by a contact Mysql table. In a facelets view I show a list of these contacts in a datatable:

      <h:outputText value="No contacts to display." rendered="#{empty contactList.contacts}" />
      <h:dataTable id="contactList" var="contact"
                rendered="#{not empty contactList.contacts}">
                <f:facet name="header">Id</f:facet>
                <f:facet name="header">Name</f:facet>
                <s:link value="#{contact.name}" view="/contacts/contact.xhtml">
                     <f:param name="contactId" value="#{contact.id}" />

      contactList is a SLSB with a method getContacts():

      public Collection<?> getContacts() {
           Query q = mudEntityManager.createNamedQuery("Contacts.All");
           return q.getResultList();

      The named query is inside my orm.xml:

      <named-query name="Contacts.All">
                select contact from Contact contact

      When I visit the view, it loads, but 34 identical queries are issued to the database:

          contact0_.contact_id as contact1_7_,
          contact0_.name as name7_,
          contact0_.contact_image_id as contact3_7_ 
          mud.contacts contact0_

      Why are so many queries being run? This particular view still loads quickly, but others, where there are difficult queries with thousands of results, take so long to load that transactions time out and the user is redirected to a debug page (after five minutes or so of waiting). If I create a query in my components.xml file, it is executed three times.