Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.databases > #137

Re: hibernate: mapping he

From "Matteo" <matteo@THRWHITE.remove-dii-this>
Subject Re: hibernate: mapping he
Message-ID <g13b0i$lq9$1@nnrp.ngi.it> (permalink)
Newsgroups comp.lang.java.databases
References <svidnRr4ioxwQKnVnZ2dnUVZ_tednZ2d@comcast.com>
Date 2011-04-27 15:21 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.databases
Lew wrote:
> 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.

Well, in fact I was referring to the business logic and to the Java 
class that enforces it. The underlying database knows nothing about this 
rule, you are right.

> Is this a MySQL database?  You didn't say.

Yes sorry, it's a MySQL db

> 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.

It was pretty late -my local time- when I posted this message. This 
morning everything sounds clearer and straightforward.
I will fake the 1-to-many relation, as the data navigation always starts 
  from a given user (any one user has 0 or more friends in his/her Set)

> 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> 
> 
That's exactly what I need.
Thanks a lot!

[btw, sorry for cross-posting. I found java.database right after having 
posted to java.help. I thought database was more appropriate]

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 | NextPrevious in thread | Next in thread | Find similar


Thread

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