persistence@glassfish.java.net

Re: how to map Self-referencing table ManyToMany relationship

From: Oleg Mayevskiy <mayevskiy_at_spendino.de>
Date: Thu, 12 Aug 2010 17:35:11 +0200

Am 12.08.2010 17:26, schrieb reljicb:
> Table link
> ==========
> nodeId1 INT
> nodeId2 INT
>
>

with this table you can safe bidirectional graph ,e.g.
node1 -> node2 : nodeId1=node1;nodeId2=node2
node2 -> node1: nodeId1=node2;nodeId2=node1

if your graph is never unidirectional and you have only bidirectional
links, you can skip the second row.

if you now want alle nodes connected to node node1, you can make such a
query:
select nodeId2 from linkTable where nodeId1=node1
union
select nodeId1 from linkTable where nodeId2=node1

query optiomations can be done, but just an idea how you could manage
your problem