0
是否有可能使一個子類(實體)從其超類(實體)重寫OneToMany映射?目前我得到「HibernateException:找到對集合的共享引用」,大概是因爲超類實體和子類實體都鏈接到同一個列表。 (我的理解是@AssociationOverride只能在超類是@MappedSuperclass而不是@Entity時使用,我不想將超類從@Entity更改爲@MappedSuperclass,因爲我希望超類的表和查詢的能力。)Hibernate:覆蓋(實體)超類的OneToMany映射字段?
我怎樣才能讓Hibernate映射如下的東西?
@Entity
public abstract class PetOwner {
@OneToMany(targetEntity = Pet.class, mappedBy = "owner")
public <T extends Pet> List<T> getPets()
...
}
@Entity
public abstract class Pet {
@ManyToOne(targetEntity = PetOwner.class)
@JoinColumn(name = "owner_id", referencedColumnName = "id")
public <T extends PetOwner> T getOwner()
...
}
@Entity
public class CatOwner extends PetOwner {
@Override
@OneToMany(targetEntity = Cat.class, mappedBy = "owner")
public List<Cat> getPets()
...
}
@Entity
public class Cat extends Pet {
@Override
@ManyToOne(targetEntity = CatOwner.class)
@JoinColumn(name = "owner_id", referencedColumnName = "id")
public CatOwner getOwner()
...
}