So I have this structure.
Table1
id
field1
field2
discriminatorValue
Table2
id
field3
Table3
id
field4
And I want to use inheritance as follows.
@DiscriminatorColumn("discriminatorValue")
@Entity
@Inheritance
@Table("Table1")
public class T1 {
@Id
private int id;
...
private String field1;
..
private String field2;
..
}
@SecondaryTable(name = "Table2", pkJoinColumns = {@PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id")})
@DiscriminatorValue("tbl2")
@Entity
public class T2 extends T1 {
private String field3;
..
}
@SecondaryTable(name = "Table3", pkJoinColumns = {@PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id")})
@DiscriminatorValue("tbl3")
@Entity
public class T3 extends T2 {
private String field4;
..
}
What I’m finding is that when I try to save a T3 object the secondary table from T2 doesn’t get included.
Thanks
Figured it out. If a secondary table has no data in any of the fields, then the row isn’t inserted.
So in my case, field3 had no data so T2 didn’t get inserted, and since the secondarytable in T3 was linked to the row in T2 the whole thing fell apart.
Oh and one other thing I’m finding is that you can’t set a default value on a field in the middle table to try to force it to be created. I.E. doing either
or
doesn’t work.
Thanks