I have an application which persists report parameters. Reports are mapped through a single table hierarchy (a wide table, but with relatively few rows). Problems arise when the same @ManyToMany mapping is used in multiple report subclasses. In this cases Hibernate schema export will generate multiple constraints for the same foreign key. This results in an error on Oracle, not allowing multiple constraints for the same foreign key.
The example below manifests the problem. Here two constraints will be generated on the table Report_TestEntity for the attribute report_id. (The same happens if I explicitly set the foreign key name through the @ForeignKey annotation.)
Does anyone know how to solve this problem?
Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@AccessType("field")
public class Report {
@Id private Long id;
}
@Entity
public class XReport extends Report {
@ManyToMany private List<TestEntity> testEntity = new ArrayList<TestEntity>();
}
@Entity
public class YReport extends Report {
@ManyToMany private List<TestEntity> testEntity = new ArrayList<TestEntity>();
}
@Entity
@AccessType("field")
public class TestEntity {
@Id private Long id;
}