Wednesday, September 09, 2009

Hibernate configuration file simple example with explanation in comments

<!DOCTYPE hibernate-configuration SYSTEM

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

      <session-factory>

            <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>

            <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/lab</property>          

            <property name="hibernate.connection.username">meridian</property>

            <property name="hibernate.connection.password">meridian</property>

 

            <!--

             | Which variant of SQL to use 

             +-->

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

 

            <!-- Use the C3P0 connection pool provider -->

            <!--

             | Minimum number of connections in the pool is 5. Atleast 5 connections should

             | be there in the pool

             +-->

            <property name="hibernate.c3p0.min_size">5</property>

            <!--

             | Maximum number of connections in the pool is 20. There are already 20 

             | connections and more connections are requested, then a runtime exception is thrown.

             | This is the only mandatory config. option for c3p0 (connection pool used by

             | hibernate out-of-the-box.

             +-->

            <property name="hibernate.c3p0.max_size">20</property>

            <!--

             | If a connection is not used for 300 seconds, remove it from the pool

             +-->

            <property name="hibernate.c3p0.timeout">300</property>

            <!--

             | Prepared statements are cached for performance benefits. If 50 prepared statements 

             | are cached, the oldest prepared statement is moved out of cache

             +-->

            <property name="hibernate.c3p0.max_statements">50</property>

            <!--

             | If a connection is idle for 3000 seconds, validate it.

             +-->

            <property name="hibernate.c3p0.idle_test_period">3000</property>

 

            <!-- Show and print nice SQL on stdout -->

            <!--

             | 1. Could also be hibernate.show_sql. 'hibernate' prefix is optional in xml files.

             | 2. Refer to org.hibernate.cfg.Environment for a list of all property names

             | 3. This could also be ...name="show_sql">${displaysql}</... Then a system property

             |    by name "displaysql" will have to be defined as in java -displaysql=true 

             +-->

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

           

            <!--

             | If the same property is specified in a properties file, this would have been

             | hibernate.show_sql = true 

             +-->

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

 

            <!--

             | List of XML mapping files

             +-->

            <mapping resource="lab/Event.hbm.xml" />

            <mapping resource="lab/Phone.hbm.xml" />

      </session-factory>

</hibernate-configuration>

No comments: