我正在開發具有持久性的Java EE應用程序。Java EE - [class <ClassName]使用非實體[類<ClassName>]作爲關係屬性中的目標實體
我汽車類有幾個預訂和預訂類擴展報價類。
由於某種原因保留不是實體類。我的猜測是繼承有問題,但我似乎無法弄清楚。
汽車看起來是這樣的:
@Entity
public class Car {
@Id
private int id;
@OneToOne(cascade=PERSIST, mappedBy="CarType")
private CarType type;
@OneToMany(cascade=REMOVE, mappedBy="Quote")
private Set<Reservation> reservations;
public Car() {}
.
.
.
public boolean equals(Object otherObject) {
...
}
public int hashCode() {
...
}
預訂看起來像這樣
@Entity
@Table(name = "Reservation")
public class Reservation extends Quote {
@Id
@GeneratedValue(strategy=AUTO)
@Column(name="reservationId")
private int reservationId;
private int carId;
public Reservation() {}
public Reservation(Quote quote, int carId) {
super(quote.getCarRenter(), quote.getStartDate(), quote.getEndDate(),
quote.getRentalCompany(), quote.getCarType(), quote.getRentalPrice());
this.carId = carId;
}
.
.
.
public boolean equals(Object otherObject) {
...
}
public int hashCode() {
...
}
}
報價看起來是這樣的:
@MappedSuperclass
public class Quote implements Serializable {
@Id
@GeneratedValue(strategy=AUTO)
@Column(name="quoteId")
private int quoteId;
@Temporal(DATE)
private Date startDate;
@Temporal(DATE)
private Date endDate;
private String carRenter;
private String rentalCompany;
private String carType;
private double rentalPrice;
public Quote() {}
public Quote(String carRenter, Date start, Date end, String rentalCompany, String carType, double rentalPrice) {
...
}
.
.
.
@Override
public int hashCode() {
...
}
@Override
public boolean equals(Object obj) {
...
}
}
爲什麼保留不是一個正確的實體類?
很好的答案。這與手動將預留添加到我的Persistence.xml中解決了問題。 –