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
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply 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: 70

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
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1282

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: 70

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Whats Wrong with my DO classes?
 
Similar Threads
Composite primary key-Exception:could not resolve property
[Hibernate] Problem with @TableGenerator
Foreign key value null if nullable true in @OneToMany assoc
ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
Creating an JPA in eclipse