posted 14 years ago
Hi all,
I was starting to learn hibernate, and found it a bit difficult to start up, and thought it would be helpful for me (and others after me) if I were to create a bit of a tutorial.
To write the tutorial, I will have to solve many problems. And once finished, i've come through a journey of learning, and I have written it all down, and will hopefully help others come through the same journey, but faster.
I am now stuck, however, with what should be a simple association. If anyone can help, i'd be very grateful;
I have the following situation:
1. A User has many contacts;
2. A Contact has many contact details
This part was easy. And I was able to get it working without trouble. I could demonstrate the one-to-many relationship between the user and his contacts, and the contact and his contact details.
This was all represented in memory by a few classes;
class User,
class Contact,
class ContactDetail
class User holds a Set of Contact types;
and class Contact holds a Set of ContactDetails types;
However, when I wanted to demonstrate how to additionally say that our User also has one contact detail himself (A main contact detail), by saying
I have not been able to work out how to represent this in the hibernate xml configuration.
The end result that I want is that my User table also has a foreign key id in its table which points to the correct primary key in my ContactDetails table.
At the moment, all i've achieved is the primary key of my User table incorrectly being joined (apparently) to the primary key of the ContactDetails table.
Here are my configurations so far;
Obviously I need something in my "<class name="sv.java.contacts.User" " element ....
I thought a 'one-to-one' element, but I can't for the life of me see how I should configure it.
Anyone? thanks in advance.
p.s. I tried to attach the project here (only 9kb) but coderanch doesn't accept .zip files .... damn)>