0
我有一个超类产品和一个子类减少。现在我想让子类覆盖超类的属性,所以它不会保留在数据库中。我鼓励它像这样工作,但显然休眠仍尝试将Reduce的ProductType属性存储在数据库中。有其他方法可以解决这个问题吗?JPA,瞬态注释不会覆盖OneToOne?
@Entity
@Table(name="PRODUCT_INSTANCE")
public class Product {
private Integer id;
protected ProductType productType;
public Product(){
}
public Product(ProductType productType) {
this.productType = productType;
}
@OneToOne
public ProductType getProductType() {
return productType;
}
public void setProductType(ProductType type) {
this.productType = type;
}
@Transient
public ProductCategory getCategory() {
return productType.getCategory();
}
}
类和子类:
@Entity
@Table(name="REDUCTION")
public class Reduction extends Product {
private ProductType type;
private Integer id;
public Reduction(Double percentage, Double totalPrice) {
ProductCategory reductionCat = new ProductCategory("_REDUCTION_", new Color("", 130, 90, 80));
type = new ProductType();
type.setBuyPrice(0.0);
type.setBtw(BTW.PER_0);
type.setCategory(reductionCat);
}
@Override
@Transient
public ProductType getProductType() {
return type;
}
}
没有,实际上没有做我想要的,AttributeOverride只是让休眠保存productType在不同的列。我想要的是,reduce类没有保存productType。 –
看看代码 – ssedano
那么即使有了这些修改,hibernate仍然抱怨说,它不能保存ProductType,因为它是一个临时对象(当它试图持久化Reduce对象时)。 –