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
Solved

hibernate native queries

Posted on 2013-11-19
3
373 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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

860 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