我使用JPA 1.0,所以我限制了我能做些什么,但我仍然认为这应该是可以做到的。然而,下面我不能得到它的工作...Hibernate的一对多抽象类覆盖ID
Table CustomerA
a_id
Table ProductB
a_id
b_id
Table ProductC
a_id
c_id
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class AbstractProduct {
@Id
@GeneratedValue....
private Long id;
private String name;
@ManyToOne()
JoinColumn(name="a_id")
private CustomerA customerA;
}
现在我想创建一个子类,可以通过乘坐Id
或创建一个基于Table A
的PK
和派生表的键组合键...
@Entity
@Table(name="ProductB")
public class ProductB extends AbstractProduct {
//@AttributeOverride(name="id", [email protected](name="B_ID") //Can only be used with MappedSuperClass and also Emmbedded Objects
//@Id //cant override the ID Column so that cant go here
//PrimaryKeycolumn join not what i want here
private Long productB_id;
private String productName;
}
@Entity
@Table(name="CustomerA")
public class CustomerA
{
@Id
@GeneratedValue....
@Column(name="a_id")
private Long aId
@OneToMany(mappedBy="customerA", cascade=CascadeType.ALL)
private Set<AbstractProduct> product;
}
所以基本上CustomerA
可以包含很多产品, 但它永远只能为ProductB
或ProductC
的。我如何可以覆盖Id
在子类中,你不能使用attributeoverride
和实体,如果你使用@Entity
只要你指定一个@Entity
必须指定@Id
。我读过的JPA维基,它看起来相当复杂,OTT在JPA 1.0实现这一点,但我想知道如果我失去了一些东西?