• 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

Native Query vs Named Query

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is it discouraged to use the native query in Hibernate . What are the disadvantages of using native query. In which case do we need to use native query.
How is caching performance affected by native query. What are advantages from performance perspective of Named Query over native query.
 
Greenhorn
Posts: 14
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
General understanding is that a Named Query (written in HQL or JPQL) is going to be optimized and converted to native sql dialect by the underlying persistence framework. A native query is something written in SQL dialect by you, over which the underlying persistence framework may not have control and hence may not be able to optimise or convert.

Further, from the hibernate spec:

You may also express queries in the native SQL dialect of your database. This is useful if you want to utilize database specific features such as query hints or the CONNECT BY option in Oracle. It also provides a clean migration path from a direct SQL/JDBC based application to Hibernate. Note that Hibernate allows you to specify handwritten SQL (including stored procedures) for all create, update, delete, and load operations (please refer to the reference guide for more information.)

 
amol skulkarni
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about Caching of native query
 
Aby Krishna
Greenhorn
Posts: 14
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It won't be cached unless you use the addScalar() or addEntity() methods.

Look: https://forum.hibernate.org/viewtopic.php?p=2373167
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic