Solved

hibernate native queries

Posted on 2013-11-19
3
357 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
  • 2
3 Comments
 
LVL 35

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 35

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now