Forums Register Login

Reason for using HQL in Hibernate

+Pie Number of slices to send: Send
Hi , Please tell me what is the reason for using HQL , when the same thing can be done with the help of normal SQL query.

Sessions createSQLQuery()


Thanks in advance .
+Pie Number of slices to send: Send
You do understand what Hibernate is for, don't you? The various databases all implement their own flavours of SQL.
+Pie Number of slices to send: Send
Homogeneous is the word .


The reason for posting this question is that somewhere i read "HQL improves performance " when compared to SQL .

I got confusion and wanted to ask how using HQL improves performance as its internally converted to SQL .


Anyway thanks Paul .

+Pie Number of slices to send: Send
HQL does not refer directly to tables in the database but instead refers to the classes that these tables are mapped to in your hibernate mapping files (or annotations). This means that your code does not need to know anything about the database that it is attached to and this is a good thing.

If you decided to port your application to another database system and, in a fit of madness, to change all the table names then all you need to change in your application are the hibernate mappings, you wouldn't need to touch any part of your code. Neat, huh?
+Pie Number of slices to send: Send
Using SQL defeat the purpose of ORM, actually the question should be why use SQL in Hibernate?

IMO, it's pity to allow to use SQL in ORM tools, what is the purpose of ORM again?
+Pie Number of slices to send: Send
 

Kieren Johnson wrote:HQL does not refer directly to tables in the database but instead refers to the classes that these tables are mapped to in your hibernate mapping files (or annotations). This means that your code does not need to know anything about the database that it is attached to and this is a good thing.

If you decided to port your application to another database system and, in a fit of madness, to change all the table names then all you need to change in your application are the hibernate mappings, you wouldn't need to touch any part of your code. Neat, huh?


The main problem is not table names, but SQL dialect. Different RDBMS use different SQL dialects.
That is the reason why Hibernate introduced HQL, SQL will be generated by Hibernate, so if we want to change RDBMS, we just change dialect instead of take a look at all SQL statements and convert SQL from dialect A to dialect B.
It's never done THAT before. Explain it to me tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1796 times.
Similar Threads
mapping problem
Table Join without Foreign Key
SQL Injection Attacks
Hql top
Hibernate with DAO?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 01:59:09.