Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2008

Tip: Looking for answers? Try searching our database.

hibernate: mapping help

Thread view: 
Matteo - 22 May 2008 01:34 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.