The growth strategy for setting the ID is sequence, specifying sequence's name, preferably one for each table sequence
For example, create a sequence:
CREATE SEQUENCE department_id_seq MINVALUE 10000 MAXVALUE 999999999999999999999999 INCREMENT by 1 nocycle;
Configuration of Hibernate mapping files:
- <?xml version= "1.0"?>
- <! DOCTYPE hibernate-mapping Public
- "-//hibernate/hibernate Mapping DTD 3.0//en"
- "Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
- <class name= "Department" table= "Department" >
- <id name= "id" column= "id" >
- <generator class= "Sequence" >
- <param name= "sequence" >DEPARTMENT_ID_SEQ</param>
- </generator>
- </id>
- <property name= "name" column= "name" type= "string"/>
- <property name= "description" column= "description" type= "text"/>
- </class>
In the Hibernate mapping file, select sequence for the ID generation policy, specify sequence's name Department_id_seq, and hibernate will automatically get department_id_ when you save the new object. SEQ. Nextval is saved to the database as the ID of the new object, so you do not need to use the trigger again to generate the ID of the new record.
Use Hibernate to automate the growth of Oracle (ID per table)