Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.databases > #136
| From | "Lew" <lew@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: hibernate: mapping he |
| Message-ID | <svidnRr4ioxwQKnVnZ2dnUVZ_tednZ2d@comcast.com> (permalink) |
| Newsgroups | comp.lang.java.databases |
| References | <g12f1t$aas$1@nnrp.ngi.it> |
| Date | 2011-04-27 15:21 +0000 |
| Organization | TDS.net |
To: comp.lang.java.databases Matteo wrote: > 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. The "Hence" clause doesn't follow - that would be the primary key even if you define a "friend" as any row in the FRIENDS table, even if the converse row is absent. There is no connection between the "AND" of the rule you stated and that primary key. In fact, nothing in the data definition you showed enforces that "A" must appear in two rows of the table, once as the "userID" and once as the "friendID". I wouldn't bother enforcing that, either. > As for MESSAGES table, both FROM and TO fields referentiate USERS.userID > (and I'm stuck with that too ) There's nothing to be "stuck with" there - it's a perfectly reasonable data design. Is this a MySQL database? You didn't say. Couldn't you just map the tables in the very straightforward way? The relation between USERS and USERS is many-to-many. Seems like you could fake it as a one-to-many, though. I don't know Hibernate well, but it seems like using <entity-name> might help. <http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping.html#mapping-entityname> The use of a join table looks like you need to read <http://www.hibernate.org/hib_docs/v3/reference/en/html/associations.html#assoc-bidirectional-join> I found pretty much your exact problem mentioned in 2005: <http://objectmix.com/jdbc-java/41501-hibernate-persons-friends-newbie-mapping-question.html> -- Lew --- * 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 — Previous in thread | 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