-->
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.  [ 3 posts ] 
Author Message
 Post subject: Multiple Inheritance Mapping
PostPosted: Tue May 13, 2008 1:54 am 
Newbie

Joined: Mon Jun 20, 2005 12:20 pm
Posts: 17
I have 2 types of objects: UserObject and SchemaObject, which are respectively shown as trees in user UI and admin UI. The problem is that I have Project class which must be in both user UI and admin UI and it has both SchemaObject and UserObject as children. Therefore, I have to refactor my class hierarchy to have multiple inheritance

Code:
AbstractObject implements IObject

UserObject extends AbstractObject {
   UserObject parent;
   Set<UserObject> children;
}

ISchema extends IObject

SchemaObject extends AbstractObject  implements ISchema{
   SchemaObject schemaParent;
   Set<SchemaObject> schemaChildren;
}

Project extends UserObject implements ISchema {
   SchemaObject schemaParent;
   Set<SchemaObject> schemaChildren;   
}

I am not comfortable with the design. Is there a better way to accomplish this? Also, I don’t know if I can use <any> mapping to define the polymorphic association between ISchema and Project. When I put <any> tag inside <class> tag, I get syntax error.

Thank you in advance,

-ZJ


Top
 Profile  
 
 Post subject: suggestions
PostPosted: Tue May 13, 2008 5:30 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
Hi,
You said that user/schema are CHILDREN of project. Doesn't this mean, in your case, that project should CONTAIN several users/schemas rather than DERIVE from them?

for example:
class Project {
Collection<User> users;
Collection<Schema> schemas;
}

?


Top
 Profile  
 
 Post subject: Re: suggestions
PostPosted: Wed May 14, 2008 1:58 am 
Newbie

Joined: Mon Jun 20, 2005 12:20 pm
Posts: 17
sagimann wrote:
Hi,
You said that user/schema are CHILDREN of project. Doesn't this mean, in your case, that project should CONTAIN several users/schemas rather than DERIVE from them?

for example:
class Project {
Collection<User> users;
Collection<Schema> schemas;
}

?


Hi Sagimann,

Yes, Project has 2 sets of children: children inherited from UserObject and schemaChildren is defined for ISchema. The following is my mapping file:

Code:
   <class name="IObject" polymorphism="explicit" abstract="true">
      <id name="objectId" column="object_id" unsaved-value="0">
         <generator class="increment" />
      </id>
      <union-subclass name="AbstractObject" abstract="true">
         <property name="name" column="name" type="string" lazy="false" />   
         <union-subclass name="UserObject" table="object">
            <many-to-one name="parent" column="parent_id" class="UserObject" />
            <set name="children" inverse="true" cascade="all-delete-orphan">
               <key column="parent_id" />
               <one-to-many class="UserObject" />
            </set>
            <union-subclass name="Project" table="project">
               <many-to-one name="schemaParent" column="parent_id" class="ISchema" />
               <set name="schemaChildren" inverse="true" cascade="all-delete-orphan">
                  <key column="parent_id" />
                  <one-to-many class="ISchema" />
               </set>
            </union-subclass>   
         </union-subclass>
         <union-subclass name="ISchema" abstract="true">
            <union-subclass name="SchemaObject" table="schema_object">   
               <many-to-one name="schemaParent" column="parent_id" class="ISchema" />
               <set name="schemaChildren" inverse="true" cascade="all-delete-orphan">
                  <key column="parent_id" />
                  <one-to-many class="ISchema" />
               </set>
            </union-subclass>
         </union-subclass>
      </union-subclass>
   </class>


I don't know how to use <any> mapping to associate ISchema and Project.

Thanks,
-ZJ


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

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.