1.

Explain Querying in Hibernate?

Answer»

The Generator class is used to generate ids for the PERSISTENT class OBJECTS. These unique ids are inserted into the mapped table as primary key values. All the generator classes implement the org.hibernate.id.IdentifierGenerator interface. The default generator classes provided by the Hibernate Framework are as below: 

  1. Assigned: is supported by all databases and is the default generator class 
  2. Increment: is supported by all databases and uses the formula of max id value of database + 1 
  3. Sequence: is not supported in MySQL. It reads next value of a database sequence and then returns that value as id to the hibernate. If there is no sequence in the database, it uses the default sequence 
  4. Hilo: is used to generate ids of types short, int and long. It uses the LOW and high algorithm. Hilo is a shortcut name for the TableHiloGenerator class.  
  5. Native: It uses the identity, sequence or hilo generator classes to generate ids depending on the TYPE of database. 
  6. Identity: it is used in databases like Sybase, MS SQL etc to support the id column. The id that is returned is of type short, int or long. The database has the responsibility of generating the unique identifier.   
  7. uuid: UUID stands for Universal Unique Identifier and is a shortcut name for AbstractUUIDGenerator class. This generates a string of 32 characters based on the starting time of the JVM, IP address of the machine, Counter value of the JVM and the system time.  
  8. foreign: This generator class is used in only ONE – to – one relationship. It returns the id of the parent as the id of the child. 

Of the above classes, assigned, increment, sequence, hilo, native, foreign and identity are used for int, long and short types of primary keys, whereas uuid is used for string type of primary keys (varchar2).  



Discussion

No Comment Found