我正在查看定义实体之间关系的示例,不确定onetomany关系中mapped by是指表列的名称还是类的名称。
@OneToMany(fetch = FetchType.LAZY, mappedBy = "company")
我正在查看定义实体之间关系的示例,不确定onetomany关系中mapped by是指表列的名称还是类的名称。
@OneToMany(fetch = FetchType.LAZY, mappedBy = "company")
以上都不是。它是关联另一侧的属性/特性的名称。例如:
public class Car {
@OneToMany(mappedBy = "theCar")
private List<Wheel> wheels;
}
public class Wheel {
@ManyToOne
@JoinColumn(name = "COL_CAR")
private Car theCar;
}
mappedBy = "theCar"
的意思是:我是双向关联的反向端,它在类Wheel
中被映射为属性theCar
。Wheel
中,这个关联定义了关联是如何映射的:使用一个名为COL_CAR
的连接列。