Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Performance Issue.

 
Mahesh Gurav
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i am using hibernate 3,& criteria API in it.I am searching members in DB on certain criteria & paginating the search result.Now problem is that when i search without any criteria query will fetch all data from table(obvious) .So query fetched more than 5000 members,which is slowing down the performance.i tried setMaxResult(500)but still prob is there.Any help available,how to use setMaxResult() or any other way for the prob.
Thnx in advance
 
Mahesh Gurav
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone there,

I am using this chunk of code now ,i want to paginate the result.still
setFirstResult(10)is working fine but criteria.setFetchSize(500); is
not.Can anyone tell right way to use setFetchSize()& setFirstResult().
MAHESH
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what DB are you using ?
did you look at the generated SQL ?
did you run the generated SQL directly ?


pascal
 
Mahesh Gurav
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi pascal,
i have posted my query in some other thread after some code change ,now scenario is as follows,
setMaxResults() & setFirstResult().
If 100 records are fetched,25 records per page i want to show it like
<prev 1 2 3 4 next> ,i can not determine how many page numbers i sholuld show if i used above mentioned two methods as they limit result size itself.
What should i do to get size of result according to which i will show pageNumbers & on click of each number i will fetch & show query result of that page by using setFirstResult() & setMaxResults().
i am using struts-hibernate3,& criteria in hibernate.
"One fellow answered to fire another query to take total count".
My question is,Is there any other option available in criteria API to get total count of reultsize.
Because DB interaction is twice if i do as the above answer(in "") suggests.
Any Suggestions!!! ,
I think my query is fine & i m using postgreSQL Database,it is result size which hampers the performance .
MAHESH
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to use a second query (check out the hibernate reference manual, they show how to count number of results without creating entities)

hibernate is based on JDBC. when you execute a HQL query/Criteria query it results in a PreparedStatement beeing executed with a limited SQL query.The answer to this SQL query, the ResultSet, does not know how many results there would be if the query would not have limits! in other words... if you ask the DB to return only 25 results it will do so... and not tell you how many results you missed.


pascal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic