aspose file tools*
The moose likes Object Relational Mapping and the fly likes one-to-one mapping problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "one-to-one mapping problem" Watch "one-to-one mapping problem" New topic
Author

one-to-one mapping problem

Somak Dalui
Ranch Hand

Joined: Apr 19, 2005
Posts: 40
I did a one-to-one mapping between two tables the following way.(unique foreign key association) :

The Sponsor_id field is in this table only.The above mapping fetches data correctly but when I am trying to update it's giving "Foreign key constraint violation" error.

Please help. Even if I do it bi-directional it gives the same error.
Halcon Guatemala
Ranch Hand

Joined: Sep 06, 2006
Posts: 57
Hi Somak, could you provide us with info about relationships between entities in your database model.

Thanks


"La verdadera sabidur´┐Ża viene del temor de Dios"
Somak Dalui
Ranch Hand

Joined: Apr 19, 2005
Posts: 40
The Main table has a foreign key for the Sponsor table (Sponsor_id).I guess that will make a one-to-one relationship.That's why I did a unique="true".What else do you need ?
Halcon Guatemala
Ranch Hand

Joined: Sep 06, 2006
Posts: 57
Hi again Somak, your foreign key attribute is'nt primary key, is it? I believe You could omit an sponsorId in MainModel, it is redundant statement:



Regards
Somak Dalui
Ranch Hand

Joined: Apr 19, 2005
Posts: 40
Thanks for the quick reply Halcon. You are right, sponsor_id is not the primary key i.e. the two tables are not sharing the same PK. I removed the line of code as you mentioned - but it's still not working.Just want to mention here that I need to keep the Sponsor_id get/set in the persistence objects.That's why I tried formula="Sponsor_id". What else can I do ?
Halcon Guatemala
Ranch Hand

Joined: Sep 06, 2006
Posts: 57
Hi again, I hope it could be helpful. I don't think you must remove the mentioned code lines, I think if Sponsor has each one an Main, why must you repeat relationship for add another attribute to Main class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: one-to-one mapping problem