Hi,
I've got an object model that makes use of interfaces to provide me effectively with multipe inheritence.
I have the following classes.
- IContext (interface)
- Location implements IContext
- Person implements IContext
- User
- UserContext ( maps User to IContext )
My IContext represents a "sphere of influence" for a user. Therefore, if I have control of an IContext I have control over it's children. A Location's children are sub-locations (e.g. UK => England => London => Warehouse => Storeroom), and a Person's children are their sub-ordinates (e.g. MD => Director => Manager => Employee => Cleaner => Mouse => Software Developer *joke*).
To do this I've created a mapping:
Code:
<hibernate-mapping ... >
<class name="IContext">
<id>...</id>
</class>
<joined-subclass name="Location" extends="IContext">
<key column="Id" />
...
</joined-subclass>
<joined-subclass name="Location" extends="IContext">
<key column="Id" />
...
</joined-subclass>
<class name="User">
<id>...</id>
<bag name="Contexts" ... >
<key column="User"/>
<one-to-many class="UserContext" />
</bag>
</class>
<class name="UserContext">
<id>...</id>
<many-to-one name="User" type="User" ... />
<many-to-one name="Context" type="IContext" ... />
</class>
</hibernate-mapping>
This all works well and I'm able to use IContext to map across a diverse set of objects to model them in a common fashion. The problem I run into is that Location and Person need to implement some other interfaces, which I also need to operate in a similar fashion to IContext. At this point I run into a problem because I can only extend a single class or interface, also a class implementing IContext may already have a parent class that isn't an IContext.
Does anyone have any ideas regarding this problem?
Would implementing a new IClassPersister to handle interfaces be a decent solution? If so, has anyone already written one? I ask this in complete ignorance of IClassPersister as I've not looked into it yet.