-->
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.  [ 2 posts ] 
Author Message
 Post subject: Fetching List of Entities that use Joined subclass strategy
PostPosted: Mon Jun 12, 2006 4:22 am 
Newbie

Joined: Wed Apr 12, 2006 7:02 am
Posts: 7
Location: Southampton, UK
Hibernate version: Hibernate 3.2.0.cr2, Hibernate Annotations 3.2.0.cr1

Name and version of the database you are using:MySQL 4.1.12-nt

I'm using the 'Joined subclass' strategy to model a hierachy like this :

Code:
public Interface IModule {...}

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class Module implements IModule {...}

@Entity
public class GamesModule extends Module {...}

@Entity
public class NewsModule extends Module {...}

@Entity
public class PollsModule extends Module {...}


The above classes are all work fine until I tried the following :

Code:
@Entity
public class Container {

   private List<IModule> _modules = new ArrayList<IModule>();

   @ManyToMany(targetEntity = Module.class)
   @JoinTable(name = "container_module",
              joinColumns = @JoinColumn(name = "container_id"),
              inverseJoinColumns = @JoinColumn(name = "module_id"))
   public List<IModule> getModules() {
      return _modules;
   }
   
   protected void setModules(List<IModule> modules) {
           _modules = modules;
    }

}


The problem is with the getModules() method. I would like this to return a list of IModule objects, but Hibernate needs to know about a concrete target entity in the @ManyToMany annotation. I've set the targetEntity to be Module.class but the problem is that I only get back instances of Module.class (the base class) and not instances of any of the subclasses.

Is it possible to get Hibernate to return a list of objects that are instances of the actual subclass its meant to be?

Any help would be much appreciated. Thanks!

John Pang


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 12, 2006 5:08 am 
Newbie

Joined: Wed Apr 12, 2006 7:02 am
Posts: 7
Location: Southampton, UK
Hi All,

The above does actually all work. The problem was with my test data, not any of the Hibernate code.

Sorry!

John Pang


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