• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is hibernate dialect, why we are using dialect in hiberate

 
Manas Ranjan Behera
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I am new to hibernate and come across the concept dialect, Can any one please explain me why we are using dialect in hibernate.

In book it is mentioned that, Hibernate uses it to find out the SQL variation by which it will talk to database.
Can any body please explain me what is this SQL variation ?


Thanks in advance
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Databases implement subtle differences in the SQL they use. Things such as data types for example vary across databases (e.g. in Oracle I might put an integer value in a number field and in SQL Server use an int field). Or database specific functionality - selecting the top n rows is different depending on the database. The dialect abstracts this so you don't have to worry about it.
 
Manas Ranjan Behera
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply
 
Arun Giridharan
Ranch Hand
Posts: 290
Debian Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't that Hibernate uses underlying jdbc to interact beside ,so why i need to specify dialect( if i don't specify it asks for it) ??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul already answered the question. So that Hibernate knows how to format the SQL statements.
 
Vadim Vararu
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun Giridharan wrote:Isn't that Hibernate uses underlying jdbc to interact beside ,so why i need to specify dialect( if i don't specify it asks for it) ??


Yes, Hibernate uses underlying jdbc to interact beside, but it has to know which jdbc driver to use (mysql, postgresql...). That's another reason to tell Hibernate which dialect to use.
 
Mohit Chouhan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Becoz when you call session.save(SomeDTO) or session.delete(SomeDTO) ...Hibernate must create a sql statement to pass to JDBC for doing the intended operation...so when we call session.save(SomeDTO) ...Dialect create the query for saving the object into the table ...
for ex...session.save(SomeDTO),Dialect would create the following sql
insert into somedto_table values(name,designation,salary)
and this sql will be then passed to the jdbc...
so we therefore definatily need a jdbc too

Here name,designation,salary are just the column names of the underlying table ...dat you must have mapped for the someDTO object...

We use different dialect...becoz every database has slight difference in its sql query...
for ex mysql can have a different insert sql query and Oracle have some other insert sql query...
so using a particular dialect would covert the save(),update(),delete() calls into database specific SQL ...
 
Ramki Sukumaran
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

So what i understand is that Dialect is a communicator to JDBC from Hibernate. So then Hibernate should have one Dialect to communicate with different Database vendor. But why is that so MySQL alone has 5 Dialect as follows.


MySQL5Dialect
MySQL5InnoDBDialect
MySQLDialect
MySQLInnoDBDialect
MySQLMyISAMDialect


Can any of you tell me what is purpose of above dialects and why is intended for.

Thanks in advance.

Regards
Ramki S


 
Paul Clapham
Sheriff
Posts: 21588
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:Databases implement subtle differences in the SQL they use.


This response from several years ago still applies. In other words, it is sometimes useful to generate different SQL depending on which MySQL database engine or version is being used.
 
Ramki Sukumaran
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul,

So what you say is that each Dialect from the mentioned list are intended for each version. Is my understanding correct? Can you please elaborate for which version each Dialect is released.

 
Paul Clapham
Sheriff
Posts: 21588
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's what I conclude. Let me say that I have never heard of those dialects so I'm making that conclusion simply based on their names.

For example I'm concluding that "MySQL5Dialect" is intended for use with MySQL version 5.

I'm drawing that conclusion because I assume that the people who named the dialects intended for the names to be meaningful. There might be a universe where the designers of Hibernate needed a dialect to work with Oracle so they called it "MySQL5Dialect", but I don't believe we live in that universe.
 
asheeshkumarrastogi kumar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:Databases implement subtle differences in the SQL they use. Things such as data types for example vary across databases (e.g. in Oracle I might put an integer value in a number field and in SQL Server use an int field). Or database specific functionality - selecting the top n rows is different depending on the database. The dialect abstracts this so you don't have to worry about it.



If i am not wrong,driver manager class is responsible for this work.not the dialect one.
if no,why there are not dialect such things in other orm frameworks like JPA,ibatis etc.
 
Tim Holloway
Saloon Keeper
Posts: 18367
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch asheeshkumarrastogi!

Yes, you are wrong. The DriverManager is responsible for locating a JDBC driver class whose name is provided to it and acting as a Factory for Connections. It takes no part in constructing or modifying SQL.

One SQL DBMS might retrieve the first 10 result rows of a query using this syntax:

Another SQL DBMS might retrieve the same 10 result rows using this syntax:

The SQL Dialect feature of the ORM that you are using, whether it's Hibernate, JPA (including Hibernate JPA), TopLink or whatever is the component that takes a request that was made in the standardized JPQL and generates the appropriate SQL for the target database.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic