当时的环境是:Struts2.1 Spring3.1
Oracle9i
用到的表Persion的定义:
create table PERSON
(
PER_ID NUMBER not null,
NAME NVARCHAR2(20),
GENDER NVARCHAR2(6)
)
tablespace USERS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64
minextents 1
maxextents unlimited
);
-- Create/Recreate primary, unique and foreign key constraints
alter table PERSON
add constraint PER_ID primary key (PER_ID)
using index
tablespace USERS
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
其中PER_ID 我定义了一个序列:
create sequence PERSON_ID_SEQ
minvalue 1
maxvalue 1000000000
start with 11
increment by 1
nocache;
然后用一个触发器将这个序列和PER_ID列关联起来:
create or replace trigger bi_person_id
before insert
on person
for each row
declare
nextid number;
begin
if :new.per_id is NULL or :new.per_id = 0 then
select PERSON_ID_SEQ.nextval into nextid from dual;
:new.per_id := nextid;
end if;
end bi_person_id;
用到的配置文件:
hibernate.cfg.xml
Person.hbm.xml
执行插入操作时就报上面的错误,然后我把Person.hbm.xml中的<generator class="identity"/>给删掉就好了