-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping polymorphic entities using interfaces: possible?
PostPosted: Tue Feb 16, 2010 5:26 pm 
Newbie

Joined: Mon Feb 15, 2010 3:09 pm
Posts: 7
Hello all,

I have the following interface and class layout:
Code:
public interface InstanceManager {
   public ManagedInstance getManagedInstance(String key);
   public void addManagedInstance(String key, ManagedInstance instance);
   public void removeManagedInstance(String key);
}

public interface ManagedInstance {
   public InstanceManager getOwner();
   // ... other methods of the managed instance
}

@Entity
public class InstanceManagerImpl implements InstanceManager {
   private long id;
   private Map<String, ManagedInstance> instances;
   
   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   public long getId() {
      return this.id;
   }
   public void setId(long id) {
      this.id = id;
   }
   
   @CollectionOfElements
   public Map<String, ManagedInstance> getInstances() {
      return this.instances;
   }
   public void setInstances(Map<String, ManagedInstance> instances) {
      this.instances = instances;
   }
   
   // other methods not important here
}

@MappedSuperclass
public abstract class AbstractManagedInstance implements ManagedInstance {
   private InstanceManager owner;
   @Target(InstanceManagerImpl.class)
   public InstanceManager getOwner() {
      return this.owner;
   }
   public void setOwner(InstanceManager owner) {
      this.owner = owner;
   }
}

@Entity
public class FirstManagedInstance extends AbstractManagedInstance {
   // ...
}
@Entity
public class SecondManagedInstance extends AbstractManagedInstance {
   // ...
}
@Entity
public class JustAnotherManagedInstance extends AbstractManagedInstance {
   // ...
}

There is a factory bean creating a suitable ManagedInstance and assigning it to the InstanceManager. The problem here is that I cannot use the @Target annotation as the concrete ManagedInstance's are mixed in the container instance, only sharing a common interface.

I know that the annotations here are not working and not complete, they are just to demonstrate the whole idea.

My questions are clear:
(1) Is this scenario possible to implement with Hibernate?
(2) If yes, how would a corrent mapping (preferrably using annotations) be done?

Thanks for any pointers you all may have!

Regards, Ernest


Top
 Profile  
 
 Post subject: Re: Mapping polymorphic entities using interfaces: possible?
PostPosted: Thu Feb 18, 2010 5:30 pm 
Newbie

Joined: Mon Feb 15, 2010 3:09 pm
Posts: 7
No answer at all?
Hmm, I had hoped some knowledgeable friend might come to help here :(


Top
 Profile  
 
 Post subject: Re: Mapping polymorphic entities using interfaces: possible?
PostPosted: Fri Feb 19, 2010 1:21 pm 
Newbie

Joined: Mon Feb 15, 2010 3:09 pm
Posts: 7
Not a single reply?
Poor forum performance...


Top
 Profile  
 
 Post subject: Re: Mapping polymorphic entities using interfaces: possible?
PostPosted: Tue Jun 21, 2011 9:35 pm 
Newbie

Joined: Tue Jun 21, 2011 9:32 pm
Posts: 1
Hi Ernest

Do you figure out this issue by yourself?

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.