Hi,
I’ve been having trouble with SecondaryTables recently.
This problem is similar to Hibernate @SecondaryTable() for both Parent and Child with the same name
I have the following data model :
@Entity
@Inheritance(strategy = SINGLE_TABLE)
public class A { [...] }
@Entity
@SecondaryTable(name = "B")
public class B extends A { [...] }
@Entity
@SecondaryTable(name = "B")
public class C extends B { [...] }
When two (or more) Secondary Tables refere to the same table in a hierarchy, Hibernate will insert for each entity, instead of inserting once and then updating the table. This causes a unique constraint violation on the data base.
I know the simple answer to this is to change the model for a more hibernate friendly model.
For some context, I’m working on migrating an old management application to hibernate, thus cannot change the model that easily.
For now, the fix I’ve found is to create an hibernate Interceptor that looks for entities mapped with @SecondaryTable, and change the SqlInsert with an update statement if a Secondary Table is already declared on the same table in the hierarchy.
Do you plan on handling this kind of secondary table mapping in future versions of hibernate ?