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"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
 <class name="hib.Contact" table="CONTACT">
 <id name="id" type="long" column="ID" >
 <generator/>
 </id>

 <property name="firstName">
 <column name="FIRSTNAME" />
 </property>
 <property name="lastName">
 <column name="LASTNAME"/>
 </property>
 <property name="email">
 <column name="EMAIL"/>
 </property>
 </class>
</hibernate-mapping>

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

hibernate-mapping

Root element of this mapping

class

maps the java class and SQL table

id

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

name:

The property name used by the persistent class.

column:

The column used to store the primary key value.

type:

The Java data type used.

unsaved-value:

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.

generator

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

Increment:

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

Sequence:

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

Assigned

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

property

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

Advertisements

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s