[英]Java Persistence api: class uses non-entity class as target entity in the relationship attribute
[英]Java EE - [class <ClassName] uses a non-entity [class <ClassName>] as target entity in the relationship attribute
我正在開發具有持久性的 Java EE 應用程序。
我的Car類有一些Reservation ,而Reservation類擴展了Quote類。
出於某種原因, Reservation不是實體類。 我的猜測是繼承有問題,但我似乎無法弄清楚。
汽車看起來像這樣:
@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) {
...
}
}
為什么Reservation不是正確的實體類?
實體 Reservation 必須刪除 @id 因為女兒從超類繼承它
指定一個類,其映射信息應用於從它繼承的實體。 映射的超類沒有為其定義單獨的表。
我通過做以下事情解決了這個問題:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.