Hibernate Oracle sequence Skills
- 2020-06-23 02:08:47
- OfStack
1. First create sequence in Oracle sequence
create seq_idminvalue 1start 1increment by 1cache 20;
2, in your ES18en.xml configuration
seq_id
When the data is inserted again, Hibernate will automatically generate the following statement:
hibernate: select seq_id.nextval from hibernate: insert into YXJK.T_YXJK_WHRYTXL (XM0000, ZW0000, LXDH00, SJHM00, DZYJ00, IP0000, ID0000) values (? ,? ,? ,? ,? ,? ,?)
The next sequence value is automatically generated and the object is inserted into the table. It is important to note that Hibernate requires the primary key of sequence to be 1, either shor, long, or integer.
2. Another way is to use the common sequence, in which sequence for the table can be specified at any time. Then the corresponding ES62en.xml is as follows:
Then create the common sequence object, named hibernate_sequence
create sequence hibernate_sequence
minvalue 0
maxvalue 99999999
start with 10000
increment by 1;
3. Notes
If the database is migrated from another database, such as sqlserver, then the starting value for sequence should be larger than the maximum value for ID in the current table, otherwise an error will occur, as sequence does not maintain duplicates of the previous values.
1. sequence: For Oracle database
The sequence of
2. native: used across databases and generated by the underlying dialect.
Default. sequence hibernate_sequence
Note: When using native, Hibernate defaults to looking for the hibernate_sequence sequence in Oracle. If there is no such sequence in Oracle, an error will be reported with the Oracle database.