Hello all,
I'm fairly new to hibernate, though I'm not new to ORM concepts.
I read the official h8 version 3 tutorial, as well as other articles and
examples out there.
Now the problem is that I can't figure out how the best way to map the
following tables:
table USERS (
`userID` int(11) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`lastName` varchar(255) NOT NULL,
`nickname` varchar(20) NOT NULL,
PRIMARY KEY (`userID`),
KEY `nickname` (`nickname`) ---> indice
)
table FRIENDS (
`userID` int(11) unsigned NOT NULL default '0',
`friendID` int(11) unsigned NOT NULL default '0',
PRIMARY KEY (`userID`,`friendID`),
KEY `friendID` (`friendID`),
CONSTRAINT `friends_ibfk_1` FOREIGN KEY (`userID`) REFERENCES `users`
(`userID`),
CONSTRAINT `friends_ibfk_2` FOREIGN KEY (`friendID`) REFERENCES `users`
(`userID`)
)
table MESSAGES (
`messageID` int(11) unsigned NOT NULL auto_increment,
`from` int(11) unsigned NOT NULL,
`to` int(11) unsigned NOT NULL,
`message` varchar(4000) default NULL,
PRIMARY KEY (`messageID`),
KEY `from` (`from`),
KEY `to` (`to`),
CONSTRAINT `messages_ibfk_1` FOREIGN KEY (`from`) REFERENCES `users`
(`userID`),
CONSTRAINT `messages_ibfk_2` FOREIGN KEY (`to`) REFERENCES `users`
(`userID`)
)
I'm stuck with my implementation of the "friendship" relationship, as I
decided to define it with a directed-graph, thus user.A and user.B are
"friends" if and only if
( FRIENDS.userID = user.A ; FRIENDS.friendID = user.B ) AND (
FRIENDS.userID = user.B ; FRIENDS.friendID = user.A )
Hence, the composite-id (userID, friendID) of FRIENDS table.
As for table MESSAGES, both FROM and TO referentiate USERS.userID (and I'm
stuck with that too )
Thanks in advance!
Matteo
Lew - 22 May 2008 03:59 GMT
> Thanks in advance!
Please do not multi-post. It's irritating to answer a post in one group and
find it separately posted elsewhere, and it doesn't help the conversation to
fragment it all over Usenet.

Signature
Lew