Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query Execution in Hibernate

 
Vaibhav G Garg
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • 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
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • 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.



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic