我與註釋應該設置怎樣我JPA實體類和去掙扎,其中如何設置JPA實體類?
我有以下表格:
Table Customer {
id: primary key,
name
}
Table CustomerDimension {
id: primary key, foreign key(Customer.id),
detail
}
目前,我有以下實體類:
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@Column(name = "name")
private String name;
@OneToOne
private CustomerDimension customerDimension;
}
public class CustomerDimension {
// ? what is meant to go here?
private long id;
@Column(name = "detail")
private String detail;
}
爲了讓我插入一個擁有新CustomerDimension的新客戶,需要註釋CustomerDimension.id
?
應該CustomerDimension
也有參考回Customer
?
只是把'@ Id',因爲你有一個單向關係 – Ramanlfc
@Ramanlfc-不是一個雙向關係,我可以從CustomerDimension - > Customer,反之亦然? – Cheetah
您還需要在兩個類上添加註釋'@ Entity'和'@ Table'。 –