Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

hibernate native queries

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
gudii9
Asked:
gudii9
  • 2
1 Solution
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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
 
gudii9Author Commented:
>> 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
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now