In my current project I have a inheritance structure that looks like this:
@Entity
@Table(name="groups")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorValue("G")
@DiscriminatorColumn(name="group_type")
public class Group{ //some annotations removed
private Long id;
private String name;
private Set<Subject> subjects;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="parent_group_id")
private Group parent; ##### tree parent ####
@OneToMany(cascade=CascadeType.ALL, mappedBy="parent")
private Set<Group> subGroups; ##### tree children #####
...
}
My Group
objects can have kind of a tree like structure by containing a list of other Group
objects.
As some groups are a bit special, there is a second class that extends this class:
@Entity
@DiscriminatorValue("C")
@Table(name="fix_groups")
public class FixGroup extends Group{
private Layout lay;
private Set<Person> instr;
...
}
I tried to use a joined multi table approach (as described here: http://en.wikibooks.org/wiki/Java_Persistence/Inheritance#Joined.2C_Multiple_Table_Inheritance) but it seems not to work with a non abstract superclass like Group
!
I get the following exception:
Caused by: java.lang.ClassCastException: org.hibernate.mapping.JoinedSubclass
cannot be cast to org.hibernate.mapping.RootClass
Is there a solution apart from declaring Group
as abstract and making a new class Group2
that only extends it?
And if I did so, would this self-reference Set<Group> subGroups
still cause problems?