Jakarta ee Richfaces不必要地访问数据库

Jakarta ee Richfaces不必要地访问数据库,jakarta-ee,richfaces,toplink,Jakarta Ee,Richfaces,Toplink,我有一个简单的CRUD项目,我正在使用richfaces和toplink。我注意到一些页面的加载速度相当慢,所以我将toplink的日志记录级别设置为FINE。加载在rich:datatable中列出所有课程对象的“我的页面”时,toplink似乎运行了9次相同的“全选”查询。当使用rich:datascroller移动到下一组50个项目或对列进行排序时,它再次运行相同的select all查询18次以上 以下是数据表: <rich:dataTable value="#{CourseCon

我有一个简单的CRUD项目,我正在使用richfaces和toplink。我注意到一些页面的加载速度相当慢,所以我将toplink的日志记录级别设置为FINE。加载在rich:datatable中列出所有课程对象的“我的页面”时,toplink似乎运行了9次相同的“全选”查询。当使用rich:datascroller移动到下一组50个项目或对列进行排序时,它再次运行相同的select all查询18次以上

以下是数据表:

<rich:dataTable value="#{CourseController.courses}"
                        id="table"
                        var="dataTableItem"
                        rendered="#{CourseController.courses.rowCount>0}"
                        rows="50"
                        onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
                        onRowMouseOver="this.style.backgroundColor='#dcdcdc'">
            <f:facet name="header">
                <h:outputText value="Courses"/>
            </f:facet> 
            <rich:column sortBy="#{dataTableItem.id}">  
                <f:facet name="header">  
                    <h:outputText  value="ID"/>  
                </f:facet>  
                <h:commandLink action="#{CourseController.viewCourse}">  
                    <h:outputText value="#{dataTableItem.id}" /> 
                    <f:param name="id" value="#{dataTableItem.id}" />  
                </h:commandLink>
            </rich:column> 
            <rich:column sortBy="#{dataTableItem.name}">  
                <f:facet name="header">  
                    <h:outputText  value="Name"/>  
                </f:facet>  
                <h:outputText value="#{dataTableItem.name}" />  
            </rich:column>        
            <rich:column sortBy="#{dataTableItem.owner}">  
                <f:facet name="header">  
                    <h:outputText  value="Owner"/>  
                </f:facet>  
                <h:outputText value="#{dataTableItem.owner}" />  
            </rich:column>
            <rich:column rendered="#{LoginController.inSystemAdminGroup || LoginController.inOperationsManagerGroup || LoginController.inLogisticsCoordinatorGroup}">  
                <f:facet name="header">  
                    <h:outputText  value=""/>  
                </f:facet>  
                <h:commandLink action="#{CourseController.editCourse}">  
                    <h:outputText value="Edit/Delete"/>  
                    <f:param name="id" value="#{dataTableItem.id}" />  
                </h:commandLink>  
            </rich:column>
            <f:facet name="footer">
                <rich:datascroller id="datascroller" />
            </f:facet>
        </rich:dataTable>
getCourses()函数调用my bean中get的函数:

public List<Course> findAll() {
        System.out.println("Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!");
        Query q = em.createQuery("select object(o) from Course as o WHERE o.deleted = FALSE ORDER BY o.name");
        List<Course> courses = q.getResultList();
        return courses;
    }

JSF规范不保证每个生命周期请求只调用一次getter,不要在getter中放入昂贵的代码(即,在每次调用getCourses时,您都在执行查询并创建数据模型,JSF规范允许根据框架对每个请求的要求调用此方法).

是否有最佳实践来显示我正在尝试的所有项目?我应该将对象保存在内存中,并将它们存储到数据库中吗?我将让多个用户同时编辑这些项目,因此我需要一种方法来保持所有内容的同步。在我开始使用Seam之前,我曾添加一个显式的“刷新”按钮,该按钮会点击db,现在我使用Seam事件模型和outjection。
public List<Course> findAll() {
        System.out.println("Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!");
        Query q = em.createQuery("select object(o) from Course as o WHERE o.deleted = FALSE ORDER BY o.name");
        List<Course> courses = q.getResultList();
        return courses;
    }
Im in getCourses.  Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
        bind => [false]
Im in getCourses.  Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
        bind => [false]
Im in getCourses.  Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
        bind => [false]
Im in getCourses.  Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
        bind => [false]
Im in getCourses.  Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
        bind => [false]
Im in getCourses.  Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
        bind => [false]
Im in getCourses.  Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
        bind => [false]
Im in getCourses.  Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
        bind => [false]
Im in getCourses.  Fun Fun Fun.
Selectin all the courses in the freaking database!!!!!!!!!!!!!!!!!!!!!!
SELECT ID, MODIFIEDBY, ACRONYM, EMSID, DELETED, REMINDEREMAILTEXT, DATEADDED, NUMDAYSREMINDER, DATEDELETED, ADHOC, DATEMODIFIED, ADDEDBY, OWNER, DELETEDBY, OPTLOCK, NAME FROM COURSE WHERE (DELETED = ?) ORDER BY NAME ASC
        bind => [false]