• 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

Query Execution in Hibernate

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

We are developing a web based application using Hibernate ORM.

For optimal performance, which of the following way we should be using for DB Queries:

i. Native SQL

ii. Criteria Query

iii. Named Queries

iv. HQL

Please reply at the earliest with the pros/cons of each one.

Thanks,
vaibhav garg
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
-Use the native SQL for things that hibernate was not really built for like batch queries (it can be done but its not what an ORM is designed for) or in some cases Stored Procedures.
-Prefer Criteria queries for dynamic queries. In this case there is no need to to parse before generating. This makes it superior to concatenating HQL together, using a string builder (this should be avoided). They are also type safe if you are using the JPA criteria API.
-Named queries are the best performing as they are generated and parsed only once. Use these for frequent queries that are not dynamic. HQL also has the benefit of being easier to read than criteria queries.
-Non-named queries must be parsed and generated each pass, for infrequent queries this is fine, but otherwise I would go with one of the other options.



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