Easy learning with example program codes

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.


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

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

Related Topics:

How to build java project using ant in eclipse?
JAXB marshalling – convert java object to xml example.
How to create pdf file in java using iText jar?
Generics class example.
OGNL in struts 2.
Hibernate One-to-One Mapping using xml.
Send inline image in email using JavaMail API.
Quartz 2 JobListener example.


Sign Up/ Sign In
Ask a Question

Copyright © 2018 CodesJava Protection Status SiteMap Reference: Java Wiki