单边多对一: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关系,即不设置级联保存

posted @ 2018-04-20 21:35  車輪の唄  阅读(8)  评论(0编辑  收藏  举报  来源