Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Many to One instead of One to One relationship

 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have two tables in the database which have a one to one relationship between them.
However when i generate the annotated POJOs using Netbeans IDE, a many to one is generated instead of One to One.

Here are the database script.



Because of some complexities, i cannot make A_ID as the primary key in the table B.
So, A_ID is made the unique key and is made not null and unique and then joined with A.

Here are the Pojos that are generated.



Why is a Many To One generated instead of one to one.
I dont really need B or Set of Bs in A, so i can remove it in A.
However in B, i would have preferred One to One with A(although it is almost the same as Many to One with A_Id being unique and not null).

Can somebody help me out on that.

Thank you
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object models and data models are very different things. Any object model from data model generator is just going to give you one of the possible objects models for the data model. It just see the constraint so guesses it is a ManyToOne. If you want it to be a OneToOne then just change the generated code. The code is just meant to get you started, normally you would want to design a proper object model based on your application requirements.
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks James.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic