Configuration and Mapping Files
Configuration and Mapping are very familiar keywords we used to hear in the hibernate, every hibernate program must need these 2 xml files.
Configuration:
Configuration is the file loaded into an hibernate application when working with hibernate, this
configuration file contains three types of information.
1. Connection Properties
2. Hibernate Properties
3. Mapping file name(s)
We must create one configuration file for each database we are going to use, suppose if we want
to connect with two databases, like Oracle, MySql, then we must create two configuration files.
No. of databases we are using = that many number of configuration files
We can write this configuration in two ways…
1. XML
2. writing Properties file.
We don’t have annotations here, actually in hibernate 1, 2.x we defined this configuration file by
writing .properties file, but from 3.x xml came into picture.
So, finally
Mapping File : XML, annotations
Configuration File : XML, .properties (old style)
Take a look upon few needed properties of configuration file
connection.driver_class
JDBC driver class e.g. com.mysql.jdbc.Driver
connection.url
JDBC URL e.g. jdbc:mysql://localhost:3306/mydb
connection.username
database user e.g. root
connection.password
database user password e.g. root
show_sql
Write all SQL statements to console e.g. true | false
dialect
particular relational database dialect name
This property makes Hibernate generate the appropriate SQL
for the chosen database.
e.g. org.hibernate.dialect.MySQLDialect (this is for MYSQL)
hbm2ddl.auto
Automatically validates or create or update schema
DDL to the database when the
SessionFactory is created.
e.g. validate | update | create | create-drop
hibernate.connection.pool_size
Limits the number of connections waiting in the Hibernate
database connection pool.
e.g. 5 | 6
hibernate.connection.autocommit
Allows autocommit mode to be used for the JDBC connection.
e.g. true | false