I have some questions on relationship mapping. here is the db config:
Code:
CREATE TABLE tContactInfoType
(
id int(8) auto_increment not null primary key,
InfoType varchar (20)
);
INSERT INTO tContactInfoType VALUES
(1,'Home'),
(2,'Work'),
(3,'Fax'),
(4,'Mobile'),
(5,'Alt1'),
(6,'Alt2'),
(7,'Main'),
(8,'E-mail');
CREATE TABLE tContactType
(
id int(8) auto_increment not null primary key,
ContactType varchar (20)
);
INSERT INTO tContactType VALUES
(1,'Billing'),
(2,'Office');
CREATE TABLE Contacts
(
id int(8) auto_increment not null primary key,
xid int (8),
Last varchar (100),
First varchar (100),
Middle varchar (100),
Title varchar (100),
Type int(8)
);
CREATE TABLE ContactInfo
(
id int(8) auto_increment not null primary key,
xid int (8),
ContactInfo varchar (100),
Type int (8),
Private Boolean
);
Here is a sample select:
Code:
mysql> select * from Contacts, ContactInfo where ContactInfo.xid = Contacts.id order by ContactInfo.xid, ContactInfo.type;
+----+------+---------+---------+--------+-------+------+----+------+----------------------------------------+------+---------+
| id | xid | Last | First | Middle | Title | Type | id | xid | ContactInfo | Type | Private |
+----+------+---------+---------+--------+-------+------+----+------+----------------------------------------+------+---------+
| 1 | 20 | Fooo | Bar | W | | 1 | 11 | 1 | 111-222-3333 | 2 | false |
| 1 | 20 | Fooo | Bar | W | | 1 | 1 | 1 | foobar@gmail.com | 8 | false |
+----+------+---------+---------+--------+-------+------+----+------+----------------------------------------+------+---------+
one to one relationship: Contacts.Type - tContactType.id
one to one relationship: ContactInfo.Type - tContactInfoType.id
one to many relationship: Contacts.id -> ContactInfo.xid
My vision of how the data looks is:
Code:
Carlson, Peter - Office Contact
111-222-3333, Office
222-333-4444, Fax
peter@foo.bar, email
Smith, John - Billing Contact
333-444-5555, Office
444-555-6666, Fax
js@foo.bar, email
I can't figure out how to make the class object for this or the hbm file. I dont need someone to write my code :) but a couple of lines of it would be nice
Here is the hbm file for Contacts:
Code:
<class name="DBO_Contacts" table="Contacts">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="xid"/>
<property name="Last"/>
<property name="First"/>
<property name="Middle"/>
<property name="Title"/>
<one-to-one name="Type" class="DBO_tContactType" />
</class>
However I get an error: "Duplicate property mapping of Type found in dbObjects.DBO_ContactInfo"
What do I do for the one-one relationships?
Also not sure how to define the one to many yet. I'm thinking something like:
Code:
<set name="ContactInfo" table="CONTACTINFO">
<key column="id"/>
<many-to-many column="XID" class="ContactInfo"/>
</set>
Peter