Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Whats Wrong with my DO classes?

 
Avinash Ga
Ranch Hand
Posts: 78
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

i am trying to do a cascade insert using hibernate with jpa. Here are my DO classes.

Person Class.....



Address Class.....



if i try to persist these do's like this.....


where person is....


i am getting the following exception.

javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: INSERT on table 'ADDRESS' caused a violation of foreign key constraint 'FK1ED033D4A2C3AF45' for key (9). The statement has been rolled back.
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1361)
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289)
org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:78)
com.mycomp.personproject.dataaccessobject.PersonDao.save(Unknown Source)

can you please help me understanding the mapping? can anyone tell me what am i missing here?
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is foreign key constraint 'FK1ED033D4A2C3AF45' for key (9) ? I don't see any reason why this would not run. I would initialize the address list and use add rather than set the whole list, but despite that what you have should insert 2 rows in Address and one row in Person. Maybe post your ddl.
 
Avinash Ga
Ranch Hand
Posts: 78
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your time Bill,

Actually when i run this program in Derby DB, its creating new Foreign key constraints in Address table. I dont know why it is doing this. i will run this program for MS-Sql and try to analyse the problem. I will update soon.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic