Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.databases > #135
| From | "Matteo" <matteo@THRWHITE.remove-dii-this> |
|---|---|
| Subject | hibernate: mapping help |
| Message-ID | <g12f1t$aas$1@nnrp.ngi.it> (permalink) |
| Newsgroups | comp.lang.java.databases |
| Date | 2011-04-27 15:21 +0000 |
| Organization | TDS.net |
To: comp.lang.java.databases
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 MESSAGES table, both FROM and TO fields referentiate USERS.userID
(and I'm stuck with that too )
Thanks in advance !
Matteo
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
Back to comp.lang.java.databases | Previous | Next — Next in thread | Find similar
hibernate: mapping help "Matteo" <matteo@THRWHITE.remove-dii-this> - 2011-04-27 15:21 +0000
Re: hibernate: mapping he "Lew" <lew@THRWHITE.remove-dii-this> - 2011-04-27 15:21 +0000
Re: hibernate: mapping he "Matteo" <matteo@THRWHITE.remove-dii-this> - 2011-04-27 15:21 +0000
Re: hibernate: mapping he "Lew" <lew@THRWHITE.remove-dii-this> - 2011-04-27 15:21 +0000
Re: hibernate: mapping he "Matteo" <matteo@THRWHITE.remove-dii-this> - 2011-04-27 15:21 +0000
Re: hibernate: mapping he "Lew" <lew@THRWHITE.remove-dii-this> - 2011-04-27 15:21 +0000
csiph-web