Solved

hibernate native queries

Posted on 2013-11-19
3
396 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 500 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

622 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