5 Replies Latest reply on Jun 12, 2009 3:17 PM by Narin Kalra

    Entity Query is getting fired twice

    Narin Kalra Newbie

      Hi i am using rich:datatable  with rich:datascroller. When i click next page in the datascroller, query is fired twice. I mean it goes to the entityQuery class twice. Is something wrong with the rich:datatable or entity Query?


        • 1. Re: Entity Query is getting fired twice
          Leo van den berg Master


          I cant't help you if you don't give any code, so just the piece of the page (not complete, just the attributes) and the Query you have.


          • 2. Re: Entity Query is getting fired twice
            Narin Kalra Newbie
            Hi Leo,

            Following is some of the code i am using in my xhtml page, I have mapped the value attribute to my commonListManager class which returns the dataModel to the table

            XHTML code

            <rich:dataTable  var="ecEntity" binding="#{commonListManager.dataTable}" id="ecdt" onRowClick="onRowClick(this);" onRowDblClick="onRowDblClick(this);" value="#{commonListManager.pagedDataModel}" rows="30">
            <rich:column id="pur2" style="width:150px;">
            <f:facet id="pur2_ecfchdr" name="header">
            <span id="pur2_echdrtxt" align="left" style="width:150px;text-align:left;">Purchase Order</span>
            <h:outputText value="#{ecEntity.purCode}"/>

            Following is the method of my java class which is mapped to data table

            public DataModel getPagedDataModel(){
                 ECEntityQueryManager ecEntityQueryManager = new ECEntityQueryManager();

                 log.info("First Row is: " + dataTable.getFirst());
                 log.info("Rows to fetch: " + dataTable.getRows());
                 List pagedList = ecEntityQueryManager.getPaginatedResultSet(dataTable.getFirst(), dataTable.getRows());
                    log.info("Size of the pagedList is: " + pagedList.size());
                 //Get the total number of records in the entity
                 int totalCount = ecEntityQueryManager.getResultCount().intValue();
                 log.info("Total Number of records in the entity: " + totalCount);
                 ECListDataModel dataModel = new ECListDataModel(pagedList, totalCount, dataTable.getRows());
                      return dataModel;

            Following is the method i have written in my EntityQuery class:
                 public List getPaginatedResultSet(Integer firstResult, Integer maxResult){
                      return getResultList();

            Hope this will help you understand the structure i am using.

            • 3. Re: Entity Query is getting fired twice
              Leo van den berg Master


              Maybe you should use the default behaviour of the Seam EntityQuery class? It is not very clear why you create an ECEntityQuerymanager because an EntitManager is automatically available through injection (@In)

              Any standard combination of Rich:Datatable/scroller and the SeamQuery component works out of the box, paginating the results and proving the DataModel thought Seam @dataModel annotation. So basically I don't see a reason to write your own components to do that.

              look into the examples directory of your Seam distribution.


              • 4. Re: Entity Query is getting fired twice
                Joshua Davis Expert

                I think Leo is right.   IIRC the SeamQuery components have getters that return cached result lists.   I'd have to look at my code to be sure, but if that's the case, then the problem is simple: your getter is doing the query every time and it's called more than once by the page.

                • 5. Re: Entity Query is getting fired twice
                  Narin Kalra Newbie

                  Actually, as per my understanding problem is not with the dataModel class, but its dataScroller which is making query to execute again.