Show light on Hibernate mapping file

This is in continuation of my previous post.

Lets take the hibernate mapping file and get to the tags used in that file.

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

 <class name="hib.Contact" table="CONTACT">
 <id name="id" type="long" column="ID" >

 <property name="firstName">
 <column name="FIRSTNAME" />
 <property name="lastName">
 <column name="LASTNAME"/>
 <property name="email">
 <column name="EMAIL"/>

We could see some XML tags tries forms this mapping. Their explanations are given below.


Root element of this mapping


maps the java class and SQL table


This will handle the primary key constraint. In addition this is the unique representation of an object.
Attributes of ID elements are given below.


The property name used by the persistent class.


The column used to store the primary key value.


The Java data type used.


This is the value used to determine if a class has been made persistent. If the value of the id attribute is null, then it means that this object has not been persisted.


This is the notification to generate the primary key. The following values to this attribute decides the type of generator


generate primary keys of type long, short or int that are unique only. It should not be used in the clustered deployment environment.


Hibernate can also use the sequences to generate the primary key. It can be used with DB2, PostgreSQL, Oracle, SAP DB databases.


Assigned method is used when application code generates the primary key.


The property elements define standard Java attributes and their mapping into database schema. The property element supports the column child element to specify additional properties, such as the index name on a column or a specific column type

One thought on “Show light on Hibernate mapping file

  1. Pingback: GrassField» Blog Archive » Increment with hibernate generator

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s