This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Many to One instead of One to One relationship Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Many to One instead of One to One relationship" Watch "Many to One instead of One to One relationship" New topic
Author

Many to One instead of One to One relationship

Rahul Babbar
Ranch Hand

Joined: Jun 28, 2008
Posts: 210
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


Rahul Babbar
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
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.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Rahul Babbar
Ranch Hand

Joined: Jun 28, 2008
Posts: 210
Thanks James.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Many to One instead of One to One relationship
 
Similar Threads
JPA Multiple Foreign Key Join
Multiple Column Join
Why is Hibernate creating a unique constraint when I don't want one?
Hibernate: java.lang.ClassCastException: java.util.GregorianCalendar
how to update OneToMany