-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Criteria performance
PostPosted: Wed Jun 24, 2009 4:38 am 
Newbie

Joined: Wed Jun 24, 2009 4:26 am
Posts: 1
I have a question about criteria. In a webpage, I only need display first 20 rows. When we create a criteria for a class. Then we set first result and fetch size. Does the underlying JDBC fetchs all rows and criteria just iterator its and return the targeted rows. In this way, does JDBC result set consumes a lot of JVM memory?

Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Application.class);
criteria.setFirstResult(11).setFetchSize(10).list();


Top
 Profile  
 
 Post subject: Re: Criteria performance
PostPosted: Wed Jul 08, 2009 4:30 am 
Newbie

Joined: Wed Jul 08, 2009 4:14 am
Posts: 1
Location: germany
According to my experience so far, criteria query with first/maxResults set is too slow!

Our construct for pagination:
1. create Hibernate Query object
Code:
Query q = getSession().createQuery("from MyEntity");

2. derive a ScrollableResults object
Code:
ScrollableResults scroll = q.scroll();

3. scroll to first result and build paging *manually* (no kidding, it's the fastest way, we found)
Code:
            List result = new ArrayList();
            scroll.first(); // <- about the necessity of this I'm not sure at the moment, might be ok to skip
            scroll.scroll(startRow);
            int i = 0;
            while (i < rowsPerPage && scroll.next()) {
                result.add(scroll.get(0));
                i++;
            }


Please notify me if you find out any more about this problem and performance regards.

Thanks.


Top
 Profile  
 
 Post subject: Re: Criteria performance
PostPosted: Tue May 24, 2011 4:19 pm 
Newbie

Joined: Tue Dec 09, 2008 11:55 am
Posts: 7
if you use Spring JDBC template for pagination, it will work fast .. I implemented and tested . but I don't know why use Criteria... with hibernate that slow... if use hibernate native sql can be possible to have performance issue to be solved ?

any idea?

Thanks in advance


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.