0 votes
in JAVA by
What is Hibernate Configuration File?

1 Answer

0 votes
by

Hibernate configuration file includes the database-specific configurations that are required to begin database connection using hibernate framework. 

The configuration file is usually an XML document with the name hibernate.cfg.xml. We provide database credentials or JNDI resource information in the hibernate configuration XML file. Some other important parts of hibernate configuration file are Dialect information, so that hibernate knows the database type and mapping file or class details.

Here is a sample hibernate.cfg.xml file:

<!DOCTYPE hibernate-configuration PUBLIC

        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"

        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- JDBC Database connection settings -->

        <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>

        <property name="connection.url">jdbc:mysql://localhost:3306/hibernate_db?useSSL=false</property>

        <property name="connection.username">root</property>

        <property name="connection.password">root</property>

        <!-- JDBC connection pool settings ... using built-in test pool -->

        <property name="connection.pool_size">1</property>

        <!-- Select our SQL dialect -->

        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>

        <!-- Echo the SQL to stdout -->

        <property name="show_sql">true</property>

        <!-- Set the current session context -->

        <property name="current_session_context_class">thread</property>

        <!-- Drop and re-create the database schema on startup -->

        <property name="hbm2ddl.auto">create-drop</property>

        <!-- dbcp connection pool configuration -->

        <property name="hibernate.dbcp.initialSize">5</property>

        <property name="hibernate.dbcp.maxTotal">20</property>

        <property name="hibernate.dbcp.maxIdle">10</property>

        <property name="hibernate.dbcp.minIdle">5</property>

        <property name="hibernate.dbcp.maxWaitMillis">-1</property>

        <mapping class="net.javaguides.hibernate.entity.Student" />

    </session-factory>

</hibernate-configuration>

Related questions

0 votes
asked Apr 14, 2023 in JAVA by SakshiSharma
0 votes
asked May 7 in JAVA by SakshiSharma
...