DisplayTag分页与Hibernate分页 [英] DisplayTag pagination vs Hibernate Pagination

查看:110
本文介绍了DisplayTag分页与Hibernate分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显示标签提供给定对象的分页功能。 Hibernates提供的选项是每页仅抓取所需的记录。我的项目中我们使用了这两个概念。



显示标签:
我需要获取所有记录根据过滤标准并将其存储在会话中。然后,这个displaytag将关心所有的分页和排序。所以Httpsession包含大量的数据。



Hibernate:
它只提取请求的数据库。需要为每个请求打开会话。



什么是最佳做法?或者如果我们可以实现这两个事情怎么做?请帮助解决此问题。

正如您所概述的那样,使用DisplayTag,您需要获取所有所有结果并将它们放入会话中。所以你只做一个(可能很昂贵的)查询,但是从内存的角度来看,这不能很好地扩展(如果你需要获取大量的结果或者增加并发用户的数量)。 >

另一方面,使用Hibernate,可以使用 setFirstResult setMaxResult 仅提取每页实际显示的记录。这需要为每个页面执行一个查询,但是会根据无限数量的结果进行扩展。



就个人而言,我更喜欢第二种方法,大多数用户不会浏览所有页面(为什么要加载所有结果) - 并使用 Hibernate中的分页和EJB3



如果您决定坚持第一种方法,我会实施某种最大结果数量限制以避免过于昂贵的查询。如果查询超出限制,请求用户执行更严格的搜索,即添加标准(谁将浏览数千个结果?)。

如果你需要所有的结果,例如为了报告目的,那么DisplayTag和Statefull会议都不是我认为的正确工具。


Display Tag provides pagination feature from the given object. Hibernates provides option to fetch only required record per page.In My project we are using both the concept.

Display Tag: I need to fetch all the record based on the filter criteria and store it in the Session. Then this displaytag will take care about all pagination and sorting.So Httpsession holds lot of data.

Hibernate: It fetches only the requested no of Objects from the database.Need to open session for every request.

What is the Best way of doing?Or if we can acheive both the things how to do that? Please help on this.

解决方案

As you outlined, with the DisplayTag you need to fetch all the results and to put them in the session. So you're doing only one (potentially expensive) query but this won't scale well from a memory point of view (if you need to fetch a high number of results or if you increase the number of concurrent users).

On the other hand, with Hibernate, you can use setFirstResult and setMaxResult to fetch only the records actually shown on each page. This requires to perform a query for each page but will scale for an infinite number of result.

Personally, I prefer the second approach that I find more memory efficient - especially since most users don't browse all pages (so why loading all results) - and use the pattern described in Pagination in Hibernate and EJB3.

If you decide to stick with the first approach, I'd implement some kind of max results number limit to avoid too expensive queries. If a query goes beyond the limit, ask the user to perform a more restrictive search i.e. to add criteria (who is going to browser several thousands of results anyway?).

And if you need all the results, for example for reporting purposes, then neither the DisplayTag nor the statefull session is the right tool in my opinion.

这篇关于DisplayTag分页与Hibernate分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆