Following are the generator Hibernate Classes available in hibernate assigned, increment, sequence are regularly used generator classes, assigned is the by default class.
For Example,
<id name="employeeId" column="eid"> <generator class="assigned"/> </id>
It selects maximum of existing id from a table, increments the value one by one and then returns the Id to Hibernate. This class follows the one formula like max(Id)+1. Increment Generator class is also Database Independent.
For Example,
<id name="employeeId" column="id"> <generator class="increment"/> </id>
When configuring the sequence Generator, if user defined sequence name is passed as a parameter then Sequence generator class reads next value of that sequence from Database and returns it as an Id to the Hibernate. Sequence Generator Class is Database dependent.
For Example,
<id name="employeeId" column="eid"> <generator class="sequence"/> </id>
If a user does not pass sequence value, then Hibernate will generate predefined sequence “hibernate_sequence“.
column: It contain a next_hi by the default value.
max_lo: It contains 32767 by the default value.
max_lo value*next_lo value+next_lo value.
Eg:Id generating second time means 32767*1+1=32768.
For Example,
<id name="employeeId" column="eid"> <generator class="sequence"/> </id>
If generator class is not mapped in mapping file, then Hibernate will take default values.
It will create a big String. If an object is read from Database table, then it will pass the long String on Object. Hence, this generator class is not useful.