我有这样的映射:
<!-- language: java -->
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
class CommonResource {
// mapping to all parents here
}
class CommonResourceChild extends CommonResource { }
class Parent1 {
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "parent1_common_resource_type1",
joinColumns = {@JoinColumn(name = "parent1_id")},
inverseJoinColumns = {@JoinColumn(name = "common_resource_id")})
List<CommonResource> commonResourcesType1;
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "parent1_common_resource_type2",
joinColumns = {@JoinColumn(name = "parent1_id")},
inverseJoinColumns = {@JoinColumn(name = "common_resource_id")})
List<CommonResource> commonResourcesType2;
}
class Parent2 { //almost the same mapping, but with another parent
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "parent2_common_resource_type1",
joinColumns = {@JoinColumn(name = "parent2_id")},
inverseJoinColumns = {@JoinColumn(name = "common_resource_id")})
List<CommonResource> commonResourcesType1;
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "parent2_common_resource_type2",
joinColumns = {@JoinColumn(name = "parent2_id")},
inverseJoinColumns = {@JoinColumn(name = "common_resource_id")})
List<CommonResource> commonResourcesType2;
}
@Inheritance(strategy = InheritanceType.JOINED)
abstract class AbstractParent3 { } // not every Parent3 have CommonResource
class Parent3Impl extends AbstractParent3 {
// some Parent2 can have CommonResource or it's children
@OneToOne(cascade = CascadeType.ALL)
CommonResourceChild commonResourceChild;
}
是否有可能以某种方式根据以下几点将每个CommonResource实体及其子类型映射到不同的父母?
我可以自由更改映射或修改数据库,因为我还没有发布它。 :)