Is there a way to naturally map the Java
implements keyword ?
There are many ways to map the Java extends keyword (class, subclass, joined-subclass, and union-subclass).
I would like to model the interfaces required by a software component that follows the dependency inversion principle, as defined by Desmond D'Souza in Objects, Components, and Frameworks (1998) amazon link
http://www.amazon.com/Objects-Component ... 0201310120
and by Agile Software by Martin (2002)
http://www.amazon.com/Software-Developm ... 0135974445
If this is available,
I can supply a set of hibernate mapping files that can be used without modification by implementing classes, much like a Java class can implement an interface without the interface knowing who implements it.
The closest Hibernate comes to this is with the <any> tag. That tag requires the developer to modify the
<any> <meta-value /> tag for each implementation of the interface, which breaks the Dependency Inversion Principle.
With the
extends support, I can only implement one interface, because that is the restriction imposed by
extends. I have multiple software components that externalize different behavior with persistent references. Those references are to objects that are exported by the underlying software components. (
archiving and
version control for example)
I would like to have something like this:
Code:
public interface Archivable
{
public Long getEntityId();
public Archive getArchive();
public void setArchive(Archive archive);
}
Code:
public interface VersionedDocument
{
public Long getEntityId();
public VersionState getVersionState();
public void setVersionState(VersionState versionState);
}
Code:
public class SomeBusinessObject implemnts Archivable, VersionedDocument
{
private Long entityId;
private Archive archive;
private VersionState versionState;
public Long getEntityId() {}
public void setEntityId(Long id) {}
public Archive getArchive() {}
public void setArchive(Archive archive) {}
public VersionState getVersionState() {}
public void setVersionState(VersionState versionState) {}
}
Then my BusinessObject Hibernate mapping would look something like this:
Code:
<class name="SomeBusinessObject">
<id> ... </id>
<many-to-one name="archive" />
<many-to-one name="versionState" />
<implements interface="Archivable" />
<implements interface="VersionedDocument" />
</class>
My archive software component mapping would look like this:
Code:
<interface name="Archivable">
<id name="entityId" /> <!-- obtained through interface definition -->
<many-to-one name="archive" />
</interface>
<class name="Archive">
<id>...</id>
<one-to-interface name="Archivable" />
</class>
And my versioned document software component would look like this:
Code:
<interface name="VersionedDocument">
<id name="entityId" /> <!-- obtained through interface definition -->
<many-to-one name="versionState" />
</interface>
<class name="VersionedState">
<id>...</id>
<one-to-interface name="VersionedDocument" />
</class>
The mapping would be very much like the
any keyword, except that the
type value specified in the any tag by
Code:
<meta-value value="TBL_ANIMAL" class="Animal"/>
would instead be the fully-qualified classname of the entity mapping that contains the <implements> tag.