开发者社区 > 云原生 > 正文

DubboService 和 @Transactional 一起配置事务失效

环境信息

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

展开
收起
大圣东游 2023-05-11 16:45:35 234 0
1 条回答
写回答
取消 提交回答
  • 这个和 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

    2023-05-12 10:40:16
    赞同 展开评论 打赏

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载