环境信息
Dubbo version: 3.0.10 Operating System version: win7 Java version: 1.8
步骤重现
@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class) @Slf4j @EnableJpaRepositories(basePackages = "com.xiushang") //用于扫描Dao @Repository @EntityScan("com.xiushang.entity") //用于扫描JPA实体类 @Entity @ServletComponentScan(basePackages = {"com.xiushang.filter"}) @EnableRedisHttpSession @EnableDubbo @EnableTransactionManagement(proxyTargetClass = true) public class AdminApplication extends SpringBootServletInitializer {
public static void main(String[] args) throws Exception { ConfigurableApplicationContext application = SpringApplication.run(AdminApplication.class, args); }
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(AdminApplication.class); }
}
@DubboService(interfaceClass=CustomService.class,filter = "userFilter",retries = 0) public class CustomServiceImpl extends BaseServiceImpl implements CustomService {
@Transactional(readOnly = true)
public PageTableVO findPageList(CustomSearchVo searchPageVo) {
...
Page<CustomEntity> page = findPageList(ex, searchPageVo.createPageRequest(new Sort.Order(dir, "lastContactDate")));
LazyLoadUtil.fullLoad(page);
PageTableVO vo = new PageTableVO(page, searchPageVo);
return vo;
}
}
代码使用了JPA,CustomEntity 中有延迟加载的属性,因此需要session
期待结果
能正常返回,并延迟加载 CustomEntity中所有属性
实际执行情况
amic=true, service.filter=userFilter, anyhost=true},}, cause: org.apache.dubbo.remoting.RemotingException: Failed to send response: Response [id=6, version=2.0.2, status=20, event=false, error=null, result=AppResponse [value=com.xiushang.framework.entity.vo.PageTableVO@6fc8a7cf, exception=null]], cause: java.lang.RuntimeException: failed to lazily initialize a collection of role: com.xiushang.entity.shop.ShopEntity.images, could not initialize proxy - no Session Java field: private java.util.List com.xiushang.entity.shop.ShopEntity.images Java field: private com.xiushang.entity.shop.ShopEntity com.xiushang.entity.custom.CustomGroupEntity.belongShop Java field: private java.util.List com.xiushang.entity.custom.CustomEntity.groupList Java field: private java.util.List com.xiushang.framework.entity.vo.PageTableVO.rowData java.lang.RuntimeException: failed to lazily initialize a collection of role: com.xiushang.entity.shop.ShopEntity.images, could not initialize proxy - no Session Java field: private java.util.List com.xiushang.entity.shop.ShopEntity.images Java field: private com.xiushang.entity.shop.ShopEntity com.xiushang.entity.custom.CustomGroupEntity.belongShop Java field: private java.util.List com.xiushang.entity.custom.CustomEntity.groupList Java field: private java.util.List com.xiushang.framework.entity.vo.PageTableVO.rowData at com.alibaba.com.caucho.hessian.io.JavaSerializer$FieldSerializer.serialize(JavaSerializer.java:304) at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeInstance(JavaSerializer.java:284) at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:251) at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:412) at org.apache.dubbo.common.serialize.hessian2.Hessian2ObjectOutput.writeObject(Hessian2ObjectOutput.java:92) at org.apache.dubbo.rpc.protocol.dubbo.DubboCodec.encodeResponseData(DubboCodec.java:225) at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.encodeResponse(ExchangeCodec.java:309) at org.apache.dubbo.remoting.exchange.codec.ExchangeCodec.encode(ExchangeCodec.java:73) at org.apache.dubbo.rpc.protocol.dubbo.DubboCountCodec.encode(DubboCountCodec.java:47) at org.apache.dubbo.remoting.transport.netty4.NettyCodecAdapter$InternalEncoder.encode(NettyCodecAdapter.java:69) at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:709) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:792) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:702)
请问最新版本dubbo 不是已经解决了DubboService 和 @transactional 的问题吗,我是缺少了什么配置吗?
原提问者GitHub用户liukefu2050
这个和 Dubbo 没啥关系,是你的 com.xiushang.framework.entity.vo.PageTableVO 不支持
看一下这篇呢:https://stackoverflow.com/questions/11746499/how-to-solve-the-failed-to-lazily-initialize-a-collection-of-role-hibernate-ex
原回答者GitHub用户AlbumenJ
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。