单边多对一:order和location
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "location_id")
private LocationDto location;
public class LocationDto {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private int type;
private String address;
private String province;
}
LocationDto locationDto = new LocationDto();
locationDto.setId(orderModelDO.getLocationId());
userOrderDto.setLocation(locationDto);
1. 保证查order时,locationDto被连带加载
2. 保存order时, 不级联保存location, 此时要设置location_id的值, 只要设置locationDto的id, 就相当于给location_id赋值
3. 此时不要设置casacade关系,即不设置级联保存