About Mapping
Mapping file is the heart of hibernate application.
Every ORM tool needs this mapping. Mapping is the mechanism of placing object properties
into column’s of a table.
Mapping can be given to an ORM tool either in the form of an XML or in the form of the
annotations.
The mapping file contains mapping from a POJO class name to a table name and POJO class
variable names to table’s column names.
While writing a hibernate application, we can construct one or more mapping files, means a
hibernate application can contain any number of mapping files.
Generally an object contains 3 properties like
1. Identity (Object Name)
2. State (Object values)
3. Behavior (Object Methods)
But while storing an object into the database, we need to store only the values (State) right ? But how to avoid identity, behavior. It’s not possible. In order to inform what value of an object has to be stored in what column of the table, will be taking care by the mapping, actually mapping can be done using 2ways,
1. XML File
2. Annotations.
(Hey friends don’t worry about annotations it is so easy, )
Syntax Of Mapping xml:
<hibernate-mapping>
<class name="POJO class name" table="table name">
<id name="variable0 name" column="column name" type="java/hibernate type" />
<property name="variable1 name" column="column name" type="java/hibernate type" />
<property name="variable2 name" column="column name" type="java/hibernate type" />
</class>
</hibernate-mapping>