I think there are some problems with your model. If I'm right you want something like this:
There are Shapes. There are special (!) Shapes which can be linked by Arrows (which are Shapes).
If this is what you want then try something like this:
public class Shape{
private id
}
public class Arrow extends Shape{
private Circle fromShape;
private Circle toShape;
}
public class Circle extends Shape{
private List<Arrow> fromArrows;
private List<Arrow> toArrows;
}
The main difference that in the Circle class there is two lists, one for the Arrows pointing FROM, and one for pointing TO the Circle.
In this case you can have the follwing mapping:
Code:
<hibernate-mapping >
<class name="Shape" table="shape" abstract="true">
<id name="id" type="long" column="idShape">
<generator class="native" />
</id>
<property name="name" type="string" not-null="true"
unique="true" />
<joined-subclass name="Arrow" table="arrow">
<key column="idShape" />
<many-to-one name="fromShape" not-null="true"
column="fromShape" insert="false" update="false" />
<many-to-one name="toShape" not-null="true" column="toShape"
lazy="false" insert="false" update="false" />
</joined-subclass>
<joined-subclass name="Circle" table="circle">
<key column="idShape" />
<list name="fromArrows">
<key column="fromShape" not-null="true" />
<list-index column="fromIx" />
<one-to-many class="Arrow" />
</list>
<list name="toArrows">
<key column="toShape" not-null="true"/>
<list-index column="toIx" />
<one-to-many class="Arrow" />
</list>
</joined-subclass>
</class>
</hibernate-mapping>
and you made an association something like this
Code:
Arrow a1 = new Arrow();
Circle c1 = new Circle();
Circle c2 = new Circle();
a1.fromShape(c1);
a1.toShape(c2);
c1.addFrom(a1);//adds to from list
c2.addTo(a1);// adds to to list
session.save(c1);
session.save(c2);
session.save(a1);
as you can see first the circles are saved, and then the arrow between them
The relation between Circle from -Arrow from is bidirectional one-to-many (I was wrong in my previuos reply with many-to-many... sry)
I think this works and maybe this is what you want...
For further info you should read the Hibernate tutorial especially Chapter 7 about Association mappings and bidi one-to-many/many-to-one...
http://www.hibernate.org/hib_docs/v3/re ... tional-m21
I hope you want something like this...
Ivan