the data tableThe create table t_foo (
T_id int primary key,
T_value varchar2 (50), not null
);
-- -- -- -- -- -- -- -- -- -- -- --
sequencesThe create sequence t_foo_0
Increment by 1
Start with 1
Nomaxvalue
Nominvalue
Nocache
-- -- -- -- -- -- -- -- -- -- -- -- the trigger
The create or replace the trigger t_foo_t
Before the insert on t_foo
For each row
The begin
The select t_foo_0. Nextval into: new t_id from dual;
end;
Insert into t_foo (t_value) values (" test ");
Ps: t_id data for 9 is the insert statement execution of
-- -- -- -- -- -- -- -- --
the test codeTFoo TFoo=new TFoo ();
Foo100 tfoo. SetTValue (" ");
The Session Session.=HibernateUtils openSession ();
The Transaction ts=session. GetTransaction ();
Ts. The begin ();
The session. The save (tfoo);
Ts.com MIT ();
session.close();
You immediately after the registration number is not how many points, a great god for help
CodePudding user response:
No great god? Don't sinkCodePudding user response:
No great god?CodePudding user response:
Not in theory, the code must have been one t_foo_0. Nextval, search the program t_foo_0. Nextval, or read data read 2 records, and in the end you just insert a, so look sequence + 2CodePudding user response:
The trigger should add a condition of the building Lord
The create or replace the trigger t_foo_t
Before the insert on t_foo for each row
When (new t_id is null)
The begin
The select t_foo_0. Nextval into: new t_id from dual;
end;
CodePudding user response:
Insert alone will not change the sequence of the code aboveCodePudding user response:
-- -- -- -- -- -- -- -- -- -- -- --the data tableThe create table t_foo (
T_id int primary key,
T_value varchar2 (50), not null
);
-- -- -- -- -- -- -- -- -- -- -- --
sequencesThe create sequence t_foo_0
Increment by 1
Start with 1
Nomaxvalue
Nominvalue
Nocache
-- -- -- -- -- -- -- -- -- -- -- -- the trigger
The create or replace the trigger t_foo_t
Before the insert on t_foo
For each row
The begin
The select t_foo_0. Currval into: new t_id, from dual;
The select t_foo_0. Nextval from dual;
end;
Insert into t_foo (t_value) values (" test ");
It should go, take out the current value first, and then call the nextval
CodePudding user response:
Note: because the primary key on the hibernate