1

I am new to Hibernate. While reading Hibernate, I came across the Dialect property. Whatever database we will use in our application, we need to set dialect related to that database and Hibernate will generate appropriate query related to that database.

Just want to know if it is the mandatory property to be set? If it is not and not specified in the hibernate.cfg.xml file, then how will Hibernate generate the SQL queries i.e. which database compliant SQL query will be generated?

Anand
  • 20,708
  • 48
  • 131
  • 198

3 Answers3

1

No it is not mandatory as per documentation http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/session-configuration.html#configuration-optional-dialects , I had not try with the same. While your answer of others points I will also like to get answer from some good experienced here. :)

commit
  • 4,777
  • 15
  • 43
  • 70
  • Then what will be the default dialect? Can hibernate detect the database used using the connection.driver_class property? – Vanaja Jayaraman Mar 31 '15 at 07:55
  • please refer to the answer of Martin Andersson in this question : http://stackoverflow.com/questions/21012799/why-do-i-need-to-configure-the-sql-dialect-of-a-data-source – med_alpa Oct 25 '16 at 16:47
0

I think it's not mandatory but it's a good practice to set it in your hibernate.cfg.xml as

<property name="dialect">your dialect</property> 

posible values:

DB2                    org.hibernate.dialect.DB2Dialect
DB2 AS/400             org.hibernate.dialect.DB2400Dialect
DB2 OS390              org.hibernate.dialect.DB2390Dialect
PostgreSQL             org.hibernate.dialect.PostgreSQLDialect
MySQL              org.hibernate.dialect.MySQLDialect
MySQL with InnoDB      org.hibernate.dialect.MySQLInnoDBDialect
MySQL with MyISAM      org.hibernate.dialect.MySQLMyISAMDialect
Oracle (any version)   org.hibernate.dialect.OracleDialect
Oracle 9i              org.hibernate.dialect.Oracle9iDialect
Oracle 10g             org.hibernate.dialect.Oracle10gDialect
Sybase             org.hibernate.dialect.SybaseDialect
Sybase Anywhere    org.hibernate.dialect.SybaseAnywhereDialect
Microsoft SQL Server   org.hibernate.dialect.SQLServerDialect
SAP DB             org.hibernate.dialect.SAPDBDialect
Informix               org.hibernate.dialect.InformixDialect
HypersonicSQL      org.hibernate.dialect.HSQLDialect
Ingres             org.hibernate.dialect.IngresDialect
Progress               org.hibernate.dialect.ProgressDialect
Mckoi SQL              org.hibernate.dialect.MckoiDialect
Interbase              org.hibernate.dialect.InterbaseDialect
Pointbase              org.hibernate.dialect.PointbaseDialect
FrontBase              org.hibernate.dialect.FrontbaseDialect
Firebird               org.hibernate.dialect.FirebirdDialect
Evgeni Dimitrov
  • 21,976
  • 33
  • 120
  • 145
0

This is why...

You do not need the dialect property if you set up your database connection with hibernate configuration because hibernate does it for you:

hibernate.connection.driver
hibernate.connection.url

user configs and etc...

However, if you set up the connection with regular data source code and use hibernate you need to specify the hibernate.dialect property, because then the connection will not know what hibernate dialect.

dataSource.setdriverClassName
datasource.setUrl...
password configs and etc...
Roy Scheffers
  • 3,832
  • 11
  • 31
  • 36