Hi,
I'm trying to mix table per subclass and table per class hierarchy (using annotations) and I'm failing. I'm wondering if there is a solution
I'm trying to do the following
Code:
public class A{}
public class B extends class A{}
public class BB extends class B{}
I want A to have its own table, B to have a secondary table and BB to be in the same table as B.
I've tried the following
Code:
@Table(name="A")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue(value = "A")
public class A{}
@DiscriminatorValue("B")
@SecondaryTable(name="B", pkJoinColumns =
{
@PrimaryKeyJoinColumn(name = "aId", referencedColumnName = "aId")
}
)
public class B extends class A{
@Column(table="JobOffer")
public String getTitle(){}
}
@DiscriminatorValue("BB")
public class BB extends class B{}
@Column
public int getValue(){}
This leads to all fields in BB to be stored in table A in stead of table B.
If I try
Code:
@Table(name="A")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue(value = "A")
public class A{}
@DiscriminatorValue("B")
@SecondaryTable(name="B", pkJoinColumns =
{
@PrimaryKeyJoinColumn(name = "aId", referencedColumnName = "aId")
}
)
public class B extends class A{
@Column(table="JobOffer")
public String getTitle(){}
}
@DiscriminatorValue("BB")
@SecondaryTable(name="B", pkJoinColumns =
{
@PrimaryKeyJoinColumn(name = "aId", referencedColumnName = "aId")
}
)
public class BB extends class B{}
@Column(table="B")
public int getValue(){}
I will get a duplicate aID mySQL error trying to insert a new BB twice, once as a B and once as a BB.
If I try
Code:
@Table(name="A")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue(value = "A")
public class A{}
@DiscriminatorValue("B")
@SecondaryTable(name="B", pkJoinColumns =
{
@PrimaryKeyJoinColumn(name = "aId", referencedColumnName = "aId")
}
)
public class B extends class A{
@Column(table="B")
public String getTitle(){}
}
@DiscriminatorValue("BB")
public class BB extends class B{}
@Column(table="B")
public int getValue(){}
I will get a Hibernate error during startup.
Any ideas on how to get this working?
Kind regards,
Marc