hibernate two ways to grow IDs in Oracle
According to Hibernate's documentation, there are two ways to automate the primary key growth of entity objects.
The first: The growth strategy for setting IDs is sequence, specifying the name of sequence, preferably a sequence per table, which, like automatic growth in ms-sql,my-sql, does not need to create triggers. The specific Oracle database scripts and hibernate configuration files are as follows:
[1]oracle Data table creation script:
Java code Java Code create table department ( id number (19,0) DEFAULT ' 0 ' NOT NULL,   NAME VARCHAR2 (255) NOT NULL, description clob ); alter table Department add constraint primary_0 primary key (ID) ENABLE; alter table department add constraint uk_department_1 unique ( NAME); create sequence department_id_seq minvalue 10000 maxvalue 999999999999999999999999 increment by 1 nocycle; Java code create table department (   id number (19,0) DEFAULT ' 0 ' NOT NULL,     NAME VARCHAR2 (255) NOT NULL, DESCRIPTION CLOB ); ALTER table department add constraint primary_0 primary key (ID) ENABLE; alter table department add constraint uk_department_1 UNIQUE (NAME); create sequence Department_id_seq minvalue 10000 maxvalue 999999999999999999999999 increment by 1 NOCYCLE;
Create a department table and create a separate sequence for the department table, with the name SEQUENCE_ID_SEQ, and no triggers need to be created.
[Configuration of the 2]hibernate mapping file:
Java Code java Code <?xml version= "1.0"?> <! DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "Http://hibernate . sourceforge.net/hibernate-mapping-3.0.dtd "> Package= "Com.liyanframework.demo.domain" > <className= "Department" table= "Department" > <id "id" name= "id" > column=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>