Monday, 9 January 2017

What is hibernate configuration and mapping file?

Hibernate configuration file
It contains database specific configurations and used to initialize SessionFactory. We provide database credentials or JNDI resource information in the hibernate configuration xml file. Some other important parts of hibernate configuration file is Dialect information, so that hibernate knows the database type and mapping file or class details.

Hibernate.dialect property tells Hibernate to generate the appropriate SQL statements for the chosen database. hibernate.dialect property makes Hibernate to generate the appropriate SQL statements for the chosen database.

            <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
            <property name="connection.url">
            <property name="connection.username">root</property>
            <property name="connection.password">root</property>

            <property name="connection.pool_size">1</property>
            <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
            <property name="current_session_context_class">thread</property>
            <property name="cache.provider_class">
            <property name="show_sql">true</property>
            <property name="">validate</property>

            <mapping class="models.Category" />


Hibernate mapping file
It is used to define the entity bean fields and database table column mappings. We know that JPA annotations can be used for mapping but sometimes XML mapping file comes handy when we are using third party classes and we can’t use annotations.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...