Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

one-to-one mapping problem

 
Somak Dalui
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Somak, could you provide us with info about relationships between entities in your database model.

Thanks
 
Somak Dalui
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic