Hibernate

adplus-dvertising
ID Generator
Previous Home Next

Id generator is used to autogenerate id of objects.Different batabase support different types of generator. most commonly used generaor that are supported by oracle are:

  1. increment
  2. sequential

increment:

Increment generator uses highest value of primary key increases to generator id value.

Example:

Consider previous example of Student,in which id generator is used as:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- r4r.co.in. -->
<hibernate-mapping>
<class name="r4r.Student">
<id name="id" type="int">
<generator class="increment"></generator>
</id>
<property name="name"></property>
<property name="course"></property>
</class>
</hibernate-mapping>
Previous Home Next