Ok, it seems it is impossible to have an ordered list on one side. So I proceeded to use a composite element.
Code:
<hibernate-mapping>
<class name="bagtest.data.OneSide" table="T_OneSide">
<id name="id" column="OneSideId" type="integer">
<generator class="native"></generator>
</id>
<property name="name" type="string" column="ONS_Name"/>
<set name="othersides" table="T_Connection">
<key column="FK_OneSideId"/>
<composite-element class="bagtest.data.Relationship">
<property name="order" column="CON_Order" type="integer"/>
<many-to-one name="otherSide" column="FK_OtherSideId" class="bagtest.data.OtherSide"/>
</composite-element>
</set>
</class>
<class name="bagtest.data.OtherSide" table="T_OtherSide">
<id name="id" column="OtherSideId" type="integer">
<generator class="native"></generator>
</id>
<property name="name" type="string" column="OTS_Name"/>
<set name="onesides" table="T_Connection" inverse="true">
<key column="FK_OtherSideId"/>
<many-to-many class="bagtest.data.OneSide" column="FK_OneSideId"/>
</set>
</class>
</hibernate-mapping>
This works (although I don't like it... I would rather have a map at the "OneSide" side.) but for some reason hibernate creates duplicate entries in the database the moment i add
'sort="bagtest.RelationOrderComparator"' to the 'othersides' set. When I remove it, it works fine.
CompareTo method in
Relationship.javaCode:
public int compareTo(Object arg0) {
Relationship other = (Relationship) arg0;
// TODO Auto-generated method stub
Integer order1Int = new Integer(this.getOrder());
Integer order2Int = new Integer(other.getOrder());
return order1Int.compareTo(order2Int);
}
Compare method in
RelationOrderComparatorCode:
public int compare(Object arg0, Object arg1) {
Relationship relationship1 = (Relationship) arg0;
Relationship relationship2 = (Relationship) arg1;
return relationship1.compareTo(relationship2);
}
Some help from the team would be appreciated!
Regards,
- Vincent