Identity Algorithm

Identity Algorithm

Identity algorithm is able to generate primary key values on the basis on the underlying database table provided identity column.

Note

Identity column is a primary key Column with “auto_increment” capability.

  • This algorithm is able to provide the primary key values of the data types like short, int, long, etc.
  • This algorithm is not required any input parameter.
  • This algorithm is supported by almost all the databases which are supporting Identity column.
    • E.g MySQL.
  • To represent this algorithm, Hibernate has provided “identity” as short name and “org.hibernate.id.IdentityGenerator” as predefined class.
sql>create table emp(id primary key auto_increment, emp_name varchar2(30), salary float, address varchar2(20));

E.g

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
	<class name="com.ashok.hibernate.sample.model.Employee" table="emp">
		<id name="id" type="int" column="id">
			<generator class="identity" />
		</id>
		<property name="empName" column="emp_name" type="string" />
		<property name="address" column="address" type="string" />
		<property name="salary" column="salary" type="float" />
	</class>
</hibernate-mapping>
Identity Algorithm
Scroll to top