1
我有兩個實體,一個Customer和一個CustomerTransaction。我希望能夠將CustomerTransaction中的兩個Customer ID存儲爲外鍵(一個用於發起交易的客戶,另一個用於客戶接收)。我還希望每個Customer對象都包含它們鏈接到的所有CustomerTransaction的列表。來自同一實體的多個外鍵? (JPA休眠)
Customer.java
@Entity
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String firstName;
private String lastName;
//@ManyToOne ?
private List<CustomerTransaction> customerTransaction;
//getters and setters
}
CustomerTransaction.java
@Entity
public class CustomerTransaction {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
//@OneToMany ?
private Customer initiater;
//@OneToMany ?
private Customer receiver;
private String transactionDetails;
//getters and setters
}
如何設置了JPA註解,使每一筆交易包含客戶發起和接收的外鍵ID?
謝謝你的幫助! – DraegerMTN