Hibernate generator Element

Ads
 

Hibernate generator Element

In this tutorial you will learn about the hibernate's element.

In this tutorial you will learn about the hibernate's element.

Hibernate <generator> Element

In this tutorial you will learn about the hibernate's <generator> element.

<generator> is an optional child element of the element <id>. In <generator> a class name is to be assigned using which unique identifier is generated for the new record at the time of new record is saved. For example :

<class name="roseindia.Employee" table="employee">
<id name="empId" type="long" column="Id" >
<generator class="assigned"/>
</id>

A simple interface org.hibernate.id.IdentifierGenerator is implemented by all generators. Hibernate provides a various built-in implementations some of them built-in generators are as follows :

shortcut name for the built-in generators Description
increment For the type long, short or int identifiers are generated these
identifiers will not be remain unique if any other process inserts
data into the same table. It should not used in the
clustered environment.
identity In DB2, MySQL, MS SQL Server, Sybase and
HypersonicSQL an identity column is supported. The returned
type of an identifier may be long, short or int.
sequence In DB2, MySQL, MS SQL Server, Sybase and
HypersonicSQL an identity column is supported. The returned
type of an identifier may be long, short or int.
assigned This generator lets to assign an identifier to the object by
application before calling the save(). A default strategy if
generator element is not specified.
select This generator retrieves a primary key and primary key value
by selecting the row by some unique key that are
assigned by a database trigger
foreign This generator uses the identifier of another associated object.
Commonly used in conjunction with a primary key association.
sequence-identity Only supported by Oracle 10g drivers. It is a specialized
sequence generation strategy. For the actual value generation
it uses a database sequence.

Ads

Ads