Sunday, 27 October 2013

Named Native Query Vs Native Query Vs HQL / JPQL

there are some missing up with understanding the difference between the Native Named Query and Native Query and HQL , and a lot of headache about the the performance issue in using them.



What is the Difference between Native Query and Named Native Query :

here I will give a short notice about the difference between them
Native Query : the developer is writing a native SQL query. and has and i'ts dynamic query , it's compiled and execute in run time and will be validated each time the query is executed.
Name Native Query : the scope is persistence  ontext and can be used in the application by Specifying the Identity , and it is ready defined and Compiled once , and it's of course static statement.
they are validated only once, at the server startup

Regarding the Difference between HQL statements and Native Statements 
Native SQL is not necessarily faster than HQL. HQL finally also is translated into SQL (you can see the generated statement when running the application with the show_sql property set to true).

In some cases it can happen Hibernate / JPA  does not generate the most efficient statements, so then native SQL can be faster 
Pros and Cons Of using HQL :
Pros: 
  •  Hibernate/JPA handle the intricacies of converting the HQL into the various SQL dialects( if you write native SQL , you will lose the portability from DB to another and need to change your statements.because)
  • with native SQL you're missing the Hibernate cache - as a consequence in some cases native SQL can be slower than HQL.


Cons:
  • In some cases it can happen Hibernate / JPA  does not generate the most efficient statements, so then native SQL can be faster

What are the main differences between HQL/JPQL and Criteria ? 

 HQL is to perform both select and non-select operations on data,
Criteria is only for selecting data, we can’t perform non-select operations using criteria.

Criteria takes more time to execute than HQL.

With Criteria we are safe with SQL injection,
because of its dynamic query operation, but in HQL as your queries are either fixed or parametrized ,
there is no safe for SQL injection.
Criteria Api allows compile time checking of a query.

13 comments:

  1. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    Best Devops online Training
    Online DevOps Certification Course - Gangboard
    Best Devops Training institute in Chennai

    ReplyDelete
  2. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..
    python Online training in chennai
    python training institute in marathahalli
    python training institute in btm
    Python training course in Chennai

    ReplyDelete
  3. This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. 
    AWS training in chennai

    AWS Training in Bangalore

    ReplyDelete
  4. Useful information Thanks

    ReplyDelete
  5. I need native query information and related exceptions,if you known that please provide

    ReplyDelete
  6. I am happy for sharing on this blog its awesome blog I really impressed. thanks for sharing. Great efforts.

    Start your journey with Best SAP Course and get hands-on Experience with 100% Placement assistance from experts Trainers @Softgen Infotech Located in BTM Layout Bangalore. Expert Trainers with 8+ Years of experience, Free Demo Classes Conducted.

    ReplyDelete
  7. Nice Post! Thank you for sharing very good post, it was so Nice to read and useful to improve my knowledge as updated one, keep blogging.
    AWS training in chennai | AWS training in annanagar | AWS training in omr | AWS training in porur | AWS training in tambaram | AWS training in velachery

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete