File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes ORA-02291: integrity constraint, can not find parent key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "ORA-02291: integrity constraint, can not find parent key" Watch "ORA-02291: integrity constraint, can not find parent key" New topic
Author

ORA-02291: integrity constraint, can not find parent key

Kamil Kuchta
Greenhorn

Joined: Mar 09, 2009
Posts: 17




I don't know why, Hibernate can not find the primary key of the City which was inserted in the same session with Person. I'm using Oracle 10g.

Hibernate: select diagno.hibernate_sequence.nextval from dual
Hibernate: select diagno.hibernate_sequence.nextval from dual
Hibernate: insert into diagno.City (name, id) values (?, ?)
Hibernate: insert into diagno.Person (name, surname, city_id, id) values (?, ?, ?, ?)

Exception in thread "main" org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
.
.
Caused by: java.sql.BatchUpdateException: ORA-02291: integrity constraint (DIAGNO.PERSON_CITY_FK) violated - parent key not found
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

It appears as simple as the error. You have a constraint that says an entry can't go in unless it's associated through it's primary key with another table. Seems like you must have something null going in as the reference key.
Kamil Kuchta
Greenhorn

Joined: Mar 09, 2009
Posts: 17
Unfortunatly, there is no null...
If I get already existing city object, it works fine:


but when the city object is going to be created w person in the same session it doesn't work
Pablo Marmol
Greenhorn

Joined: Aug 23, 2010
Posts: 13
I have this, i think it is the same thing:

http://www.coderanch.com/t/533735/ORM/java/two-parents-one-child-ora

What app server are using? JPA version?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816

G. Prasad,
Your post was moved to a new topic.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Rachna Jotwani
Greenhorn

Joined: Apr 17, 2012
Posts: 2
I am getting the same error. is there any updtae on how to fix this error?
Telemart Network
Greenhorn

Joined: Apr 24, 2012
Posts: 4
Try another theme or go for latest version. Your key might not be working in this & will execute in next one.


Career Guidance Package English for Beginners
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ORA-02291: integrity constraint, can not find parent key
 
Similar Threads
one to one unidirectional mapping in jpa
Persistance issue
non-standard join in ManyToOne
EJB3/JPA @OneToOne
org.hibernate.MappingException: Could not determine type for:... with @ManyToOne