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

Hibernate query is slow

 
harikrishna kolli
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first time queries take a while to excute. I am running my application under weblogic. Do i need to set any hibernate properties to make the queries run faster. I am using session.createQuery(). Any help is appreciated
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know there is no way to "pre-issue" SQL from Hibernate to the database before the first query � you can bypass that by using stored functions/procedures. The general performance guidelines are:
  • Tune you SQL or tune your HQL to generate the best SQL; enlist the help of a DBA and/or consult something like SQL Tuning to come up with the best SQL possible (with can vary across database implementations).
  • Parameterize your SQL, rather than generating the SQL dynamically (the fact that your queries are only slow the first time suggest that you have already done this � however your SQL still may not be optimally tuned). Higher-end databases will cache the parameterized SQL � to get the full benefit your application needs to use connection sharing, i.e. all application instances logon to the DB with exactly the same user credentials.
  • The only way to bypass the "first query penalty" is to move the query into a stored function/procedure. That way the compiled function/procedure is already sitting in the database. However don't get caught in the "procedural thinking" trap inside the stored procedure/function. Properly tuned relational queries will still be much faster inside the stored procedure/function than iterating through large result-set cursors.

  •  
    Thomas Fischer
    Greenhorn
    Posts: 6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    While running your first query - after deploying your application - a instance of sessionFactory might be created. It's quite normal that this process takes some time, but this should happen only once in the life of your application.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic