I want to use Hibernate for a legacy database model.
In this model, lists are implemented with nextID, where an element points to its next element in the list or null, if it is the last element.
Legacy Tables:
GroupTab id, name,...
ElementTab id,groupID, nextID, ...
My first idea was to use a Set and maintain the nextID manually.
Code:
Group.hbm.xml snippedt
<set name="elements" inverse="true">
<key column="groupID" />
<one-to-many class="Element"/>
</set>
Code:
Element.hbm.xml snippet
<many-to-one name="group" class="Group" column="groupID"/>
<many-to-one name="next" class="Element" column="nextID"/>
This does in principle what I want, and the schema export gives me the correct DDL output.
But I feel, that is there is probably a better way to implement this.
The mapping element <list> allows me to use a list_index.
Can I use the list_index in a different way for my situation?
Is there a possibility in Hibernate which takes care of the nextID handling automatically?
Any hint, suggestion would be appreciated.
Thanks