I. There are two types of auto-increment self-segments for tables. One is that different tables use their respective Sequence. The method is as follows:
I. There are two types of auto-increment self-segments for tables. One is that different tables use their respective Sequence. The method is as follows:
I. There are two types of auto-incrementing self-segments for tables. One is that different tables use their Sequence. The method is as follows:
1. Create a sequence in Oracle sequence first
Create sequence seq_id
Minvalue 1
Start with 1
Increment by 1
Cache 20;
2. Configure in your hbm. xml
Seq_id
In this way, Hibernate will automatically generate the following statement when inserting data again:
Hibernate: select seq_id.nextval from dual
Hibernate: insert into YXJK. T_YXJK_WHRYTXL (XM0000, ZW0000, LXDH00, SJHM00, DZYJ00,
IP0000, ID0000) values (?, ?, ?, ?, ?, ?, ?)
Automatically generate the next Sequence Value and insert the object into the table. When using it, you must note that Hibernate must require shor, long, or integer for the primary key of sequence.
Another method is to use the public sequence.
In this case, you can choose not to specify the sequence used by the table. The corresponding hbm. xml content is:
Create a common sequence object named hibernate_sequence.
Create sequence hibernate_sequence
Minvalue 0
Max value 99999999
Start with 10000
Increment by 1;
3. Notes
If the database is transplanted from other databases such as sqlserver, the starting value of the sequence should be greater than the largest ID value in the current table. Otherwise, an error occurs, because sequence does not maintain whether it is the same as the existing value before the import database.
1. sequence: used for Oracle databases
Sequence name
2. native: used across databases, produced by underlying dialects.
Default. sequence is hibernate_sequence
Note: When native is used, Hibernate searches for the hibernate_sequence sequence in Oracle by default. If the sequence does not exist in Oracle, an error is returned when you connect to the Oracle database.