What is Hibernate configuration file?

Hibernate uses this file to establish connection to the database server.

  • It is an XML file which is used to define
    • DataBase connection details: Driver class, URL, username and Password.
    • Hibernate properties: Dialect, show_sql, second_level_cache ..etc
    • Mapping files names.
  • One configuration file for each database.
 Number of database’s = that many number of configuration files. 
  • Standard name for this file is hibernate.cfg.xml

Syntax of Configuration xml:

 More details on hibernate configuration file.

1. connection.pool_size : Used to configure connection pooling in hibernate.cfg.xml.            

2. show_sql : If the value is true, We can see generated sql statements in console.  

3. format_sql : If the value is true, We can see generated sql statements in a readable format.

4. use_sql_comments : If the value is true, We can see comments in generated sql statements.

 5. hbm2ddlauto: 

           create: Creates schema, destroys previous data.

           create-drop: Drops the schema at the end of a session.

           update: Updates the schema.

           validate: Validates the schema. It makes no changes to database.

6. In real time projects, developers will not define database connection details in hibernate.cfg.file.Instead they use JNDI name of data source. For example, if we want to use JNDI data source using Tomcat, the configuration will be as below.

server.xml (Tomcat server.xml (C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\server.xml))

context.xml (Tomcat server.xml (C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\server.xml))

Hibernate.cfg.xml

 

Posted in hibernate and tagged , .

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">