Hibernate mapping file

Hibernate mapping file is used by hibernate framework to get the information about the mapping of a POJO class and a database table.

It mainly contains the following mapping information:

  1. Mapping information of a POJO class name to a database table name.
  2. Mapping information of POJO class properties to database table columns.

Elements of the Hibernate mapping file:

  1. hibernate-mapping: It is the root element.
  2. Class: It defines the mapping of a POJO class to a database table.
  3. Id: It defines the unique key attribute or primary key of the table.
  4. generator: It is the sub element of the id element. It is used to automatically generate the id.
  5. property: It is used to define the mapping of a POJO class property to database table column.

Syntax:

<hibernate-mapping>
 
 <class name="POJO class name" table="table name in database">
  <id name="propertyName" column="columnName" type="propertyType" >
	<generator class="generatorClass"/>
  </id>
  <property name="propertyName1" column="colName1" type="propertyType " />
  <property name="propertyName2" column="colName2" type="propertyType " />
  ….
 </class>
 
</hibernate-mapping>

  Next Topic: Hibernate transaction management with example. Previous Topic: Object states in Hibernate with example.

 

Please follow and like us:
Content Protection by DMCA.com