Hibernate - SQL Dialects

Last Updated : 9 Apr, 2026

Hibernate Dialect is a class that acts as a bridge between Java data types and database-specific SQL types. It helps Hibernate generate SQL queries optimized for a particular database like MySQL, Oracle, etc. Since different databases have different SQL syntax, Dialect ensures compatibility and proper query conversion.

  • Enables Hibernate to generate SQL based on the selected database.
  • Produces efficient queries tailored to the database features.
  • Allows switching between different databases easily.

SQL Dialects Configuration

The SQL dialect converts the HQL query which we write in java or any other object-oriented program to the specific database SQL query. It must be configured in hibernate.cfg.xml to connect Hibernate with a particular database.

<hibernate-configuration>
<session-factory name="session-factory">
<property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
</session-factory>
</hibernate-configuration>

We can also specify in the properties file as :

hibernate.dialect=org.hibernate.dialect.DB2Dialect

hibernate.dialect property makes Hibernate generate the appropriate SQL statements for the given specific database.

Hibernate Configuration: MySQL dialect

Configuration config = new Configuration() 
.addClass(org.javabydeveloper.domain.Student.class)
.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect")
.setProperty("hibernate.connection.datasource", "jdbc:mysql://localhost:3380/<dbname>")
.setProperty("hibernate.order_updates", "true");

Configuration in hibernate.cfg.xml (MySQL8): 

 <property name="connection.url">jdbc:mysql://localhost:3380/jpa_jbd?serverTimezone=UTC&useSSL=false</property>
<property name="connection.username">user</property>
<property name="connection.password">pass</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQL8Dialect</property>

List of SQL Dialects in Hibernate

All of the Hibernate dialects are available in the org.hibernate.dialect package. Following is the popular List of SQL Dialects in Hibernate.

RDBMS

Dialects

DB2org.hibernate.dialect.DB2Dialect
DB2 AS/400org.hibernate.dialect.DB2400Dialect
DB2 OS390org.hibernate.dialect.DB2390Dialect
PostgreSQLorg.hibernate.dialect.PostgreSQLDialect
MySQL5org.hibernate.dialect.MySQL5Dialect
MySQL5 with InnoDBorg.hibernate.dialect.MySQL5InnoDBDialect
MySQL with MyISAMorg.hibernate.dialect.MySQLMyISAMDialect
Oracle (any version)org.hibernate.dialect.OracleDialect
Oracle 9iorg.hibernate.dialect.Oracle9iDialect
Sybaseorg.hibernate.dialect.SybaseASE15Dialect
Microsoft SQL Server 2000org.hibernate.dialect.SQLServerDialect
Microsoft SQL Server 2008 org.hibernate.dialect.SQLServer2008Dialect
SAP DBorg.hibernate.dialect.SAPDBDialect
Informixorg.hibernate.dialect.InformixDialect
HypersonicSQLorg.hibernate.dialect.HSQLDialect
H2 Databaseorg.hibernate.dialect.H2Dialect
Ingresorg.hibernate.dialect.IngresDialect
Progressorg.hibernate.dialect.ProgressDialect
Mckoi SQLorg.hibernate.dialect.MckoiDialect
Interbaseorg.hibernate.dialect.InterbaseDialect
Pointbaseorg.hibernate.dialect.PointbaseDialect
FrontBaseorg.hibernate.dialect.FrontbaseDialect
Firebirdorg.hibernate.dialect.FirebirdDialect

The hibernate.dialect property defines the specific Dialect class for your database. Although Hibernate can auto-detect it from the connection, explicitly setting it ensures better compatibility and correct behavior for the database version.

Comment