Integrity constraint violation: for Hibernate Insert
walter wang
Ranch Hand
Joined: Jun 02, 2001
Posts: 144
posted
0
Dear All,
I have tables designed as below, but i always get Caused by: java.sql.SQLException: Integrity constraint violation: SYS_FK_16 table: BOSS in statement [insert into COMPANY (WORKER_ID, WORKER_DEPAT_ID, BOSS_ID, BOSS_DEPAT_ID, COMPANY_ID) values (1, 2, 1, 11, 1)] at org.hsqldb.Trace.getError(Unknown Source) for insert record to table Company
Could any one give me some hints ?
CREATE TABLE WORKER ( depat_id int NOT NULL , worker_id int NOT NULL, salary decimal(20,4) NOT NULL, primary key (depat_id,worker_id) )
CREATE TABLE BOSS ( depat_id int NOT NULL , boss_id int NOT NULL, salary decimal(20,4) NOT NULL, primary key (depat_id,boss_id) )
CREATE TABLE COMPANY( company_id int NOT NULL PRIMARY KEY, boss_id int NOT NULL, boss_depat_id int NOT NULL , worker_id int NOT NULL, worker_depat_id int NOT NULL , foreign key (boss_id, boss_depat_id) references BOSS (boss_id,depat_id), foreign key (worker_id, worker_depat_id) references WORKER (worker_id,depat_id) )
public class Walter{
public boolean is_Working_Now(boolean is_boss_Coming){
return is_boss_Coming;
}
Thanks for your reply. I insert Boss first, then Insert Worker, then Insert Company Session s= SessionManager.currentSession(); Boss b1=new Boss(); b1.setComp_id(new BossPK(new Integer(1),new Integer(11))); b1.setSalary(new BigDecimal(7000));
and change the cascade from "none" to "all" for the associations from Company to the Boss and Worker.
Mark
walter wang
Ranch Hand
Joined: Jun 02, 2001
Posts: 144
posted
0
Thanks for your reply.
I modify work.hbm.xml and boss.hbm.xml cascade=all I tried many times. save(c) doesnot work. it will have exception, but if save(w1) and save(b1), it workds. i donot need to save(c).
PS: in work.hbm.xml and boss.hbm.xml to set inverse as true or false have same result. it has no effects on this case.
subject: Integrity constraint violation: for Hibernate Insert