0
我對繼承hibernate有幾個問題(單表),
外鍵是否可以在抽象類上? - 如果其中一個孩子不使用它?
車輛是否應該受到保護?
請分享任何其他想法!
謝謝!Hibernate註解 - 吸入說明
下面是一個例子:「能外鍵是在抽象類」
@Entity
@Table(name = "vehicles")
@DiscriminatorColumn(name="type")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public abstract class Vehicle {
@Id
@Column(name = "plate" ,nullable = false)
private String plate;
@OneToMany(cascade=CascadeType.ALL)
private List<EmissionInspection> insepections = new ArrayList<EmissionInspection>();
public List<EmissionInspection> getInsepections() {
return insepections;
}
...
}
@Entity
@DiscriminatorValue("POST_OFFICE_TRUCK")
@Table(name = "truck")
public class PSTruck extends Vehicle {
}
@Entity
@DiscriminatorValue("TRUCK")
@Table(name = "truck")
public class Truck extends Vehicle {
private insuranceDate;
}
@Entity
@DiscriminatorValue("PRIVATE_CAR")
@Table(name = "truck")
public class PrivateCar extends Vehicle {
private insuranceDate;
}
謝謝.......! – user648026 2012-03-16 01:34:48