I have a deep Class Hierarchy with a shallow Table hierarchy. The class hierarchy is (more or less):
Code:
@Entity
@Table(name = "ANCESTOR_TABLE")
@Inheritance(strategy = SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE", discriminatorType = STRING, length = 3)
public abstract class Ancestor
{
@Id @Column(name = "ID")
private Long id;
}
@Entity
@DiscriminatorValue("AAA")
@SecondaryTable(name = "PARENT_TABLE")
public class Parent
extends Ancestor
{
@Column(table = "PARENT_TABLE", name = "PARENT_FIELD")
private String parentField;
}
@Entity
@DiscriminatorValue("BBB")
public class Child
extends Parent
{
@Column(table = "PARENT_TABLE", name = "CHILD_FIELD")
private String childField;
}
With Eclipselink this worked as intended: Parent as well as Child have additional columns in the same secondary table.
When I try this with Hibernate 3.6, the first complaint is that table "PARENT_TABLE" is unknown during the mapping of Child. If I add a @SecondaryTable() to Child this complaint disappears, and selects work as intended. However, updates and inserts now assume an additional table which happens to have the same name as the one from Parent, resulting in 3 insert SQL statements being sent to the DB.
I think there are two issues with this:
1) If the behaviour with two @SecondaryTable annotations is intended, I think Hibernate should complain about the second secondary table having the same name as the first.
2) It appears impossible to refer to a secondary table defined in a parent class.
Switching inheritance strategy halfway would solve my problem as well (start with JOINED, continue one level down with SINGLE_TABLE) but that is not possible I guess...
Any ideas?
Bert Laverman