1

In many of document I found we have to define dialect in hibernate.cfg.xml to tell hibernate what language we are going to use in or hibernate.On the basis of this hibernate generates respective sql.

<property name="hibernate.conection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dilect">org.hibernate.dialect.MySQLDilect</property>

More over this could be possible multiple driver for any database provider and also for any driver there could be multiple dialect as per their version.

My point is even when we have already mentioned driver(unique) there and at a time we are single version of jar,then why this is not only sufficient to generate sql.

Community
  • 1
  • 1

3 Answers3

0

The dialect is an optional configuration option. Usually hibernate can autodetect a dialect based on the database connection.

But there are some cases you might want a different dialect - Different versions of database might require different Dialects. - Customize/Bugfix a dialect and specifying it.

k5_
  • 5,450
  • 2
  • 19
  • 27
  • I agree dialect could be different for each version of respective database provider,but in an application you cant use various version. –  Jun 30 '16 at 00:42
0

Are you are assuming that the Driver is unique and can be used to fin which database to connect? Well, you can have many driver classes that support the same database. May be for MySQL now there is one common driver, but consider Oracle.

There are many drivers for Oracle. Check this http://www.oracle.com/technetwork/java/index-136695.html

If Hibernate has to use any one of the possible drivers that you specify, how will it know what dialect (SQL syntax) to use? So you need to specify both the Driver class and the Dialect to Hibernate.

Shankar
  • 2,625
  • 3
  • 25
  • 49
  • yes,there could be multiple driver for a database,but why choosing any of them is not sufficient to generate respective sql. –  Jun 30 '16 at 00:44
0

Connection drive class merely point out Database Management System (DBMS) vendor. Because one DBMS, vendor has many versions, per version has a specific set of functions. By the time, per DBMS add more features. For example:

Oracle

Oracle 8i (released in 1999) use org.hibernate.dialect.Oracle8iDialect

Oracle 9i (released in 2001) use org.hibernate.dialect.Oracle9iDialect

Oracle 10g (released in 2003) use org.hibernate.dialect.Oracle10gDialect

Oracle 11g (released in 2007) use org.hibernate.dialect.Oracle10gDialect

Oracle 12c (released in 2013) use org.hibernate.dialect.Oracle12cDialect

This is full list of dialect at current version: https://docs.jboss.org/hibernate/orm/current/javadocs/org/hibernate/dialect/package-summary.html

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • I am using driver provided in 12c release,can i switch my dilect to 11g without changing my jars/mavem-dependency? –  Jun 30 '16 at 15:57
  • Check your version of Oracle database what you used. Then, dialect merely follow this version. – Vy Do Jul 01 '16 at 01:05