What is the use of a Configuration file?
Ans:
- This file acts as a container for database-related information.
- Database name, driver name, URL, username, password, etc.
- We can add database-related information using <property> tag
What is the use of dialect property?
Ans:
- The dialect specifies the database used in hibernate application.
- By using this property, hibernate framework generates the appropriate SQL query based on the database vendor.
- Dialect property allows developers to connect hibernate applications with any database vendor.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<!-- Version 8 MySQL hiberante-cfg.xml example for Hibernate 5 -->
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<!-- For old version of MySQL -->
<!-- property name="connection.driver_class">com.mysql.jdbc.Driver</property -->
<property name="connection.url">jdbc:mysql://localhost:3306/demo</property>
<property name="dialect">org.hibernate.dialect.MySQL8Dialect</property>
<property name="connection.username">root</property>
<property name="connection.password">password</property>
<!--property name="dialect">org.hibernate.dialect.MySQLDialect</property-->
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<!-- add mapping resource / -->
<mapping resource="mapping.hbm.xml" />
</session-factory>
</hibernate-configuration>
