-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate Java implements keyword support
PostPosted: Mon Feb 19, 2007 12:48 am 
Newbie

Joined: Sat Jun 10, 2006 7:50 pm
Posts: 4
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.