Hibernate generator class
Generator classes in Hibernate : -The <generator> class is a sub-element of id. It is used to generate the unique identifier for the objects of persistent class. There are many generator classes defined in the Hibernate Framework.
Note :- All the generator classes implements the org.hibernate.id.IdentifierGenerator interface. The application programmer may create one's own generator classes by implementing the IdentifierGenerator interface. Hibernate framework provides many built-in generator classes:
1.assigned : - It is the default generator strategy if there is no <generator> element . In this case, application assigns the id. For example:
2. increment :- It generates the unique id only if no other process is inserting data into this table. It generates short, int or long type identifier. If a table contains an identifier then the application considers its maximum value else the application consider that the first generated identifier is 1. For each attribute value, the hibernate increment the identifier by 1.
- Sequence :-It uses the sequence of the database. if there is no sequence defined, it creates a sequence automatically
Note :- For defining your own sequence, use the param subelement of generator.
- hilo :- It uses high and low algorithm to generate the id of type short, int and long.
- native :- It uses identity, sequence or hilo depending on the database vendor.
- identity:- It is used in Sybase, My SQL, MS SQL Server, DB2 and HypersonicSQL to support the id column.
- seqhilo :- It uses high and low algorithm on the specified sequence name.
- uuid :- It uses 128-bit UUID algorithm to generate the id. The returned id is of type String, unique within a network (because IP is used). The UUID is represented in hexadecimal digits, 32 in length.
- guid :- It uses GUID generated by database of type string. It works on MS SQL Server and MySQL.
- select :- It uses the primary key returned by the database trigger.
- foreign :- It uses the id of another associated object, mostly used with <one-to-one> association.
12. sequence-identity:- It uses a special sequence generation strategy. It is supported in Oracle 10g drivers only.