I don't know if it works semantically for your situation, but it seems that there is automatically an implied ordering to the relationship, and that should be recognized. For instance, even in your hypothetical SQL, the relation is only "interesting" in the sense that it gets you to the Person on the other side. But in order to find that Person, you need to know whether the "source" person is person1 or person2 in the relationship:
Code:
select *
from person p
left outer join relation r1 on (r1.id_person1 = p.id)
left outer join relation r2 on (r2.id_person2 = p.id)
left outer join person p2 on (p2.id = r1.id_person2)
left outer join person p1 on (p1.id = r2.id_person1)
Given that, the following seems like a workable mapping:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" >
<class name="Person" >
...
<set name="Up_Relations" >
<key column="id_Person1" />
<one-to-many class="Relation" />
</set>
<set name="Down_Relations" >
<key column="id_Person2" />
<one-to-many class="Relation" />
</set>
</class>
<class name="Relation" >
...
<property name="RelationType" />
<many-to-one name="Person1" class="Person" />
<many-to-one name="Person2" class="Person" />
</class>
</hibernate-mapping>
I'm not sure there is any way to implement a completely unordered relationship. Sometimes the order isn't needed, which is to say that while it must needs exist, it has no meaning; it may be completely arbitrary (like a generated object ID). It may be possible to "spoof" a set of relations on top of the "Up" and "Down" sets. Then simply choose a set to which new relations will be added--it doesn't matter which.
Of course, all of this is just speculation. You might research about data structures for holding vertices and their connecting edges in graph theory research--that would appear to be an exact analogue to your situation.
Good luck!