A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Arduino in Action
this week in the
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
Object Relational Mapping
Key is not present in table error hibernate
Joined: Jan 14, 2009
May 13, 2009 15:24:29
Hi, I am trying to save something into database, but i am getting this error:
14:10:12,690 INFO [STDOUT] Hibernate: select nextval ('public.delivery_restriction_history_seq') 14:10:12,690 INFO [STDOUT] Hibernate: insert into public.delivery_restriction_history (name, id) values (?, ?) 14:10:12,706 INFO [STDOUT] Hibernate: select deliveryre_.change_date as change3_29_ from public.delivery_restriction_history deliveryre_ where delive ryre_.id=? 14:10:12,706 INFO [STDOUT] Hibernate: insert into public.del_res_del_type_xref (delivery_restriction_id, delivery_type_id) values (?, ?) 14:10:12,706 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: null 14:10:12,706 ERROR [JDBCExceptionReporter] Batch entry 0 insert into public.del_res_del_type_xref (delivery_restriction_id, delivery_type_id) values (62, 343) was aborted. Call getNextException to see the cause. 14:10:12,706 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 23503 14:10:12,706 ERROR [JDBCExceptionReporter] ERROR: insert or update on table "del_res_del_type_xref" violates foreign key constraint "fk_delivery_restr iction_delivery_type" Detail: Key (delivery_restriction_id)=(62) is not present in table "delivery_restriction".
What I don't understand is that the values delivery_restriction_id = 62 delivery_type_id = 343 are clearly present from this line:
Batch entry 0 insert into public.del_res_del_type_xref (delivery_restriction_id, delivery_type_id) values (62, 343) was aborted
but why does hibernate complain that key is not present. I look in both tables (delivery_restriction and delivery_type) and the id's are there.
Here's del_res_del_type_xref's script
CREATE TABLE del_res_del_type_xref ( delivery_restriction_id integer NOT NULL, delivery_type_id integer NOT NULL, CONSTRAINT fk_delivery_restriction_delivery_type FOREIGN KEY (delivery_restriction_id) REFERENCES delivery_restriction (id) MATCH SIMPLE ON UPDATE RESTRICT ON DELETE RESTRICT, CONSTRAINT fk_delivery_type_del_res_del_type FOREIGN KEY (delivery_type_id) REFERENCES delivery_type (id) MATCH SIMPLE ON UPDATE RESTRICT ON DELETE RESTRICT ) WITH (OIDS=FALSE);
Joined: Jun 16, 2007
May 14, 2009 00:46:02
The error only says that delivery_restriction_id = 62 is not present in delivery_restriction table.
Did you check the DB? Did you run the query on delivery_restriction for id=62 and did you get any results?
Joined: Apr 14, 2004
May 14, 2009 01:44:41
iririr zz, please check your
Joined: Jan 14, 2009
May 14, 2009 10:17:16
Yes it's there, if I run this sql command manually it works fine:
insert into public.del_res_del_type_xref (delivery_restriction_id, delivery_type_id) values (62, 343)
That's what surprises me.
Author and ninkuma
Joined: Jan 10, 2002
May 14, 2009 10:31:38
"iririr zz", please check your private messages for an important administrative matter. Failure to do so will result in the removal of your account.
Books by Bear
Cameron Wallace McKenzie
author and cow tipper
Joined: Aug 26, 2006
May 15, 2009 07:59:06
I'm wondering what the primary key is for this table?
Hibernate Made Easy
What is WebSphere???
JSF 2.0 Made Easy
SCJA Certification Guides
Joined: Jan 14, 2009
May 15, 2009 08:45:56
Ok solved the problem. apparently one of my other hbm files were mapping to this table as well and it didn't like the changes when they came from the original table.
I agree. Here's the link:
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: Key is not present in table error hibernate
one to one mapping in hibernate..exception while saving.
Orphan delete doesn't seem to be working properly
comboBox sends 0 when left empty
jboss4.0.5.GA ejb3 error while persisiting one to one entity
Error in generating Sequence
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013