-->
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: Mapping of the component hierarchy (component subclasses)
PostPosted: Fri Nov 25, 2005 2:42 pm 
Newbie

Joined: Fri Nov 25, 2005 2:11 pm
Posts: 2
Hi,

I can't figure out how I would map the contained object (a component) that in turn has its own inheritance hierarchy.

In the example below the Containee class is the abstract class and is contained inside of Container class. The Containee has two subclasses:
ContaineeImplA and ContaineeImplB.

The question is how would I tell Hibernate to instantiate/persists the correct subclass of the component class? Is this possible at all? I do not
want to change the object model.


Code:
public class Contatiner {
   
   private Containee basicComponent;

   /**
    * Persistent property
    */
   public Containee getBasicComponent() {
       return basicComponent;
   }
   ...
}

public abstract Containee {
     private String someGenericProperty;
     ...
     public abstract void someMethod();
}


public ContaineeImplA {
   private String fieldA;
   public void someMethod() {
   }
   ...
}

public ContaineeImplB {
   private String fieldB;
   public void someMethod() {
   }
   ...
}


Any help would be much appreciated.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 3:23 pm 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
Could you post your table structure please? If you are not rigid on your table structure, you could aternatively use a "<one-to-one/>" strategy and then use "table per hierarchy" and discrimnators for your association.

Another option (not tried it but sounds possible) is to have a super-class for your Container with a discrimnator. The sub-classes will have the specific subclass like ContaineeImplA or ContaineeImplB. i.e.

Code:
public abstract class AbstractContatiner {
   
   private Containee basicComponent;

   /**
    * Persistent property
    */
   public Containee getBasicComponent();
}

public class ContatinerImplA extends AbstractContatiner {
   
   private ContaineeImplA basicComponent;

   /**
    * Persistent property
    */
   public Containee getBasicComponent(){

   }
}


Obviously this makes your object model less scalable and every time a new Child type is introduced you'll end up having a new Container class also.
Either way you would need to tell Hibernate how to distinguish between your sub-classe instances.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 4:04 pm 
Newbie

Joined: Fri Nov 25, 2005 2:11 pm
Posts: 2
I suspected that. Too bad that I have to modify the object model because of the limitations of the ORM tool.

Thanks.


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.