SQL Dialects in Hibernate.

SQL Dialects :-

  • Hibernate.dialect property tells Hibernate to generate the appropriate SQL statements for the chosen database.
  • Dialect class is a simple java class, which contains mapping between java language data type and database data type.
  • It contains queries format for predefined hibernate methods.
  • Hibernate generates queries for the specific database based on the Dialect class. If you want to shift from one database to another just change the Dialect class name in hibernate.cfg.xml file.
  • All Dialect classes must extend ‘Dialect’ (abstract) class
  • We can write our own dialect by extending Dialect class.
  • Dialects class is used convert HQL queries into database specific queries.

             There are some Dialects classes defined for RDBMS.

             RDBMS                                                  Dialect

            Oracle9i                            org.hibernate.dialect.Oracle9iDialect

            MySQL                              org.hibernate.dialect.MySQLDialect

            Sybase                            org.hibernate.dialect.SybaseDialect

We are define oracle dialects in hibernate.cfg.xml as below :-

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