我正在使用 Spring Boot 創建一個航空公司應用程式,并且有一個名為 Flight 的物體,它具有同一物體的兩個屬性:
public class Flight {
// more code here
@ManyToOne
@JoinColumn(name = "airport_id", referencedColumnName = "id")
private Airport startLocation;
@ManyToOne
@JoinColumn(name = "airport_id", referencedColumnName = "id")
private Airport destination;
// more code here
}
機場具有航班串列的一對多關系。
如何正確映射這種關系?Spring現在給了我錯誤:
映射通過參考未知的目標物體屬性(機場航班)
提前致謝。
uj5u.com熱心網友回復:
在機場物體內,mappedBy 參考應如下所示...
@OneToMany(mappedBy = "startLocation")
@OneToMany(mappedBy = "目的地")
uj5u.com熱心網友回復:
在Airport Entity 中定義一個關系,并指定屬性mappedBy=""。MappedBy 基本上告訴休眠不要創建另一個連接表,因為該關系已經被該關系的相反物體映射。
這基本上是指 Flight Entity 中使用的變數,如 startLocation 和目的地。它應該是這樣的:-
public class Airport {
...
@OneToMany(mappedBy = "startLocation")
private Flight flight_departure_location;
@OneToMany(mappedBy = "destination")
private Flight flight_destination;
}
它應該是這樣的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/336581.html
