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