This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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).
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.