entityManager.getReference()

执行查询时返回代理对象,这是懒加载。spring-data-jpa中对应getOne();

如果数据库中没有对应的记录,抛异常。

注:这里spring-data-jpa又任性了,getOne()不是对应get(),注意。还有更任性的,如果对象在缓存中的话,那么getOne就会返回实体对象,否则返回代理对象。

注:返回的代理对象id为0,不是请求值

原Consignee实体对象结构

private long id;
    private long userId;
    private String name;
    private String phone;
    private boolean def;

懒加载获取的代理对象中多了个handle参数, 该代理对象时不能直接使用的

在不使用get方法直接调用该代理对象会报错class com.youyunsoft.yuncai.user.dto.ConsigneeDto_$$_jvstc32_32 is not accessible

如直接使用代理对象执行 Mapper.getInstance().map(consignee, consigneeDto);

posted @ 2018-03-05 15:06  車輪の唄  阅读(20)  评论(0)    收藏  举报  来源