Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

(Hibernate operation: could not insert:

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have two tables with bi-directional association between the two. The hbm.xml files, DAOs, model classes and interfaces are all generated by middlegen. I'm constructing the objects of these generated model classes using Spring's ApplicationContext. The child object has a reference to the parent object in the spring config xml file. I try to insert an object of type child using hibernate's generated DAOs and get the following error

<error message="(Hibernate operation: could not insert: [child]): data integrity violated by SQL 'insert into child
nested exception is java.sql.SQLException: Cannot add or update a child row: a foreign key constraint fails (``, CONSTRAINT `FK9EB1B4A760778BE5` FOREIGN KEY (`parentID`) REFERENCES `parent` (`parent_id`))" type="org.springframework.dao.DataIntegrityViolationException">org.springframework.dao.DataIntegrityViolationException: (Hibernate operation: could not insert: []): data integrity violated by SQL '


Any and all help would be greatly appreciated.
- Neha.
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you're setting the parent reference on the child object.
 
Neha Gap
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The DAOs are all middlegen generated. I am not writing the code for child-parent references.

- Neha.
 
What a stench! Central nervous system shutting down. Save yourself tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic