Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

hibernate native queries

Posted on 2013-11-19
3
Medium Priority
?
404 Views
Last Modified: 2013-11-27
Hi,

I am going through below link on hibernate native queries

http://www.tutorialspoint.com/hibernate/hibernate_native_sql.htm



why we use hibernate native queries. What are advantages, disadvantages, practical uses, alternative ways to it.

please advise
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 36

Expert Comment

by:mccarl
ID: 39661458
The first sentence in the link that YOU posted puts it fairly clearly...
You can use native SQL to express database queries if you want to utilize database-specific features such as query hints or the CONNECT keyword in Oracle
Or another way, if there is something that you need to do, and you can't do it via standard HQL queries, filtering, mapping relationships, etc you can use native queries to do it in SQL.
0
 
LVL 7

Author Comment

by:gudii9
ID: 39670069
>> you can't do it via standard HQL queries, filtering, mapping relationships, etc you can use native queries to do it in SQL

Does HQL do not support standard 'queries, filtering, mapping relationships' etc. I thought HQL is more sophisticated. Please advise

I see we are using like below

StringBuilder sqlSelectCondition = new StringBuilder();
StringBuilder sqlNativeSelectCondition = new StringBuilder();



sqlSelectCondition .append(" and  A1.VENDORONE_NUM = '" + queryResult.getVendorNum().trim() + "' ");// values coming from database table
sqlNativeSelectCondition.append(" and  A1.vendoroneNum = '" + queryResult.getVendorNum().trim() + "' ");// values coming from UI xhtml
            }

I wonder how the native is different from the values coming from UI xhtml.

 Please advise
0
 
LVL 36

Accepted Solution

by:
mccarl earned 2000 total points
ID: 39679864
Does HQL do not support standard 'queries, filtering, mapping relationships' etc. I thought HQL is more sophisticated. Please advise
Think of it like this... HQL is just another layer on top of SQL. Yes it is more sophisticated in terms of you don't have to write out complex and often hard to understand SQL queries with joins etc etc to get what you want done. But it is still just a layer on top of SQL, ie. it can't do MORE things that SQL, in fact there are some things which you just can't represent in HQL, so HQL actually only provides a subset of the functionality that SQL does. This is where Native queries come in, since they are specified in SQL you can do anything that you could normally do in SQL.

Maybe think of it like this... HQL is a layer on top of SQL, just like Java is a layer on top of machine language instructions (assembly language). At some point all your Java instructions get interpretted/compiled down into machine code and get executed on the CPU. Java is good though because you can do things much easier in it than you can in machine language. However, there are just some things that you can't do in Java that you might consider dropping down to the lower-level languages like assembly language to do.

Hopefully that analogy can assist in your understanding.



I wonder how the native is different from the values coming from UI xhtml.
For this question, I have NO idea what you are asking, NO idea what your UI xhtml is...
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question