aspose file tools*
The moose likes Object Relational Mapping and the fly likes Whats Wrong with my DO classes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Whats Wrong with my DO classes?" Watch "Whats Wrong with my DO classes?" New topic
Author

Whats Wrong with my DO classes?

Avinash Ga
Ranch Hand

Joined: Aug 13, 2011
Posts: 78

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?


Avinash G.A
OCP Java SE 6 Programmer, OCP Java EE 5 Web Component Developer, OCE Java EE 6 Web Services Developer, VMware Certified Core Spring 3.x Developer, EMC Proven Professional (ISM-V2)
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

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.


[How To Ask Questions][Read before you PM me]
Avinash Ga
Ranch Hand

Joined: Aug 13, 2011
Posts: 78

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Whats Wrong with my DO classes?