• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply
 
Ranch Hand
Posts: 290
Debian Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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) ??
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul already answered the question. So that Hibernate knows how to format the SQL statements.
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ...
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 240
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Manas Ranjan Behera wrote:Hi ,
Can any body please explain me what is this SQL variation ?



This "dialect" property in the configuration file tells the hibernate to generate the appropriate SQL statements for the chosen database. For example you are using Oracle, so there are several versions of oracle as well as dialects you can use for a particular RDBMS so you define your choice. Nothing much.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic