• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate Querys.

 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Wondering if anyone can glance at this code and suggest performance tuning tips. I'm wondering more specifically instead of querying using setEntity, if theres a nother approach, like I get the ID of the entity and query by parameter. Not sure if these things make a big difference but i'm not too happy with the results i'm getting. Everything was fine while using local data of course but I cranked up mysql on a different machine on my network and trying with the same data is slower than I'd expect. Using sqlyog and running the same query returning 2 results takes 15ms.. using my hibernate application its taking 2-3 seconds..

anyway this is the code snippet..


thanks all.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should post your hibernate.cfg.xml, Hibernate version etc. and the mapping and the SQL generated from your query. You can activate SQL output in the hibernate.cfg.xml

When you use Hibernate 2 or set lazy to false then you are not only selecting from one table but may be your complete database. This is why the SQL output would be useful.
Best Regards Sebastian
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Thanks for reply.. upon further investigation, its not actually the sql thats the problem. the sql generated appears to be fine. The problem appears to be more of the cache handling. I've set the query-cache to be true and using the default cache provider. Funnily enough the time taken to process appears to be roughly the same whether i'm using the cache or not. I can tell its using the cache because i'm logging the sql. And the 2nd time it querys the sql isnt being output.

I think it might because i've got two many-to-ones in my hbm..

I'll post below. The primary object i'm listing (querying is the Contact. (I'll trim some propertys as theres quite a few)

Thanks..

 
Sebastian Hennebrueder
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The query cache is useful when
you query the same query with the same params multiple times,
have very few updates/inserts to the same

The query cache needs time for administration as well and a cached query is discarded when the table is updated. When you select 10.000 objects than your query cache has a lot to do.
When you need to query data over a LAN try to limit the resultSetof your query. (createQuery(..).setMaxResult(xxx)

Sebastian
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I really dont think the actual number of rows i'm requesting is the problem as in the case of the query that returns 2 rows, that still takes a few seconds.

Note to Sebastian, will you be releasing a paper based version of your new hibernate book ? I'm one of these guys who still prefer to hold open real pages on my lap rather than scrolling up n down a pdf. Long live paper :-)
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're using Query.list() in your code:

contacts = q.list();

If you want to take advantage of the Level 2 cache, use Query.iterate() instead. You should carefully read the hibernate documentation to fully understand the level 2 cache and how it works.

hernan
 
Sebastian Hennebrueder
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Dave,
there are two problems with paper books:
Firstly, the publisher, the distributor, the book shop all want to earn some money. The actual writer is not paid much, you cannot live from this. It is acutally barfaced (I hope the word is correct) what the writer gets at the end.
Second, I want to provide updates to the eBook. 3 months of updates are at least included and one larger update is guarantied per 3 months. So I can add the newest release information, add chapters about interesting topics (Hibernate and Stored Prodedure, Annotations, etc) or include ideas provided by other people, saying: you must include this tipp about Oracle Stored Procedure with Hibernate etc.

The second one is impossible to do with a paper book. I like paper as well and print ebooks from time to time. Apart from this I started using a second monitor. eBook on my right, IDE on my left. This works fine.

Best Regards Sebastian
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic