You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/08/15 03:01:18 UTC

[GitHub] [dubbo] liukefu2050 opened a new issue, #10459: DubboService 和 @Transactional 一起配置事务失效

liukefu2050 opened a new issue, #10459:
URL: https://github.com/apache/dubbo/issues/10459

   <!-- If you need to report a security issue please visit https://github.com/apache/dubbo/security/policy -->
   
   ### Environment
   
   * Dubbo version: 3.0.10
   * Operating System version: win7
   * Java version: 1.8
   
   ### Steps to reproduce this issue
   ```java
   @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<CustomEntity> 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
   
   
   ### Expected Behavior
   
   能正常返回,并延迟加载 CustomEntity中所有属性
   
   <!-- What do you expect from the above steps?-->
   
   ### Actual Behavior
   
   could not initialize proxy - no Session 
   <!-- What actually happens? -->
   
   If there is an exception, please attach the exception trace:
   
   ```
   
   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 的问题吗,我是缺少了什么配置吗


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] liukefu2050 commented on issue #10459: DubboService 和 @Transactional 一起配置事务失效

Posted by GitBox <gi...@apache.org>.
liukefu2050 commented on issue #10459:
URL: https://github.com/apache/dubbo/issues/10459#issuecomment-1216069212

   我感觉不会是延迟加载问题,LazyLoadUtil.fullLoad(page); 方法应该已经加载了
   
   ```
   @DubboService(interfaceClass=CustomService.class,filter = "userFilter",retries = 0)
   public class CustomServiceImpl extends BaseServiceImpl<CustomEntity> 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;
       }
   }
   
   public class LazyLoadUtil {
   
       public synchronized static void fullLoad(Object object) {
           if(object == null)
               return;
           JSON.toJSONString(object, new LazyLoadFilter());
       }
   
   
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] liukefu2050 commented on issue #10459: DubboService 和 @Transactional 一起配置事务失效

Posted by GitBox <gi...@apache.org>.
liukefu2050 commented on issue #10459:
URL: https://github.com/apache/dubbo/issues/10459#issuecomment-1216246132

   经过DEBUG,好像是序列化问题
   如下正常:
   `
         PageTableVO vo = new PageTableVO(page, searchPageVo);
           String string = JSON.toJSONString(vo, new LazyLoadFilter());
           vo =  JSON.parseObject(string,PageTableVO.class);
   
           return vo;
   `
   如下失败:
   `
          PageTableVO vo = new PageTableVO(page, searchPageVo);
           String string = JSON.toJSONString(vo, new LazyLoadFilter());
           //vo =  JSON.parseObject(string,PageTableVO.class);
   
           return vo;
   `
   那些延迟加载的属性,改如何处理?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] AlbumenJ commented on issue #10459: DubboService 和 @Transactional 一起配置事务失效

Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on issue #10459:
URL: https://github.com/apache/dubbo/issues/10459#issuecomment-1216073044

   > 我感觉不会是延迟加载问题,LazyLoadUtil.fullLoad(page); 方法应该已经加载了
   > 
   > ```
   > @DubboService(interfaceClass=CustomService.class,filter = "userFilter",retries = 0)
   > public class CustomServiceImpl extends BaseServiceImpl<CustomEntity> 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;
   >     }
   > }
   > 
   > public class LazyLoadUtil {
   > 
   >     public synchronized static void fullLoad(Object object) {
   >         if(object == null)
   >             return;
   >         JSON.toJSONString(object, new LazyLoadFilter());
   >     }
   > 
   > 
   > }
   > ```
   
   看报错是在返回的时候了,可以 debug 看下


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] liukefu2050 commented on issue #10459: DubboService 和 @Transactional 一起配置事务失效

Posted by GitBox <gi...@apache.org>.
liukefu2050 commented on issue #10459:
URL: https://github.com/apache/dubbo/issues/10459#issuecomment-1214720232

   ```java
   package com.xiushang.framework.entity.vo;
   
   import io.swagger.annotations.ApiModelProperty;
   import org.springframework.data.domain.Page;
   
   import java.util.ArrayList;
   import java.util.List;
   
   /**
    * 简单形式的分页组件
    */
   public class PageTableVO<T> extends MgPageable {
   
   	private static final long serialVersionUID = -2332973656118325329L;
   
   	/**
   	 * 数据集合
   	 */
   	@ApiModelProperty(notes = "数据集合")
   	private List<T> rowData;
   	/**
   	 * 扩展信息
   	 */
   	@ApiModelProperty(notes = "扩展信息")
   	private Object extendData;
   
   	public PageTableVO() {
   	}
   	public PageTableVO(Page page,PageTableVO vo) {
   		if(page!=null){
   			setRowData(page.getContent());
   			setTotalCount(page.getTotalElements());
   		}
   		if(vo!=null){
   			setPageNo(vo.getPageNo());
   			setPageSize(vo.getPageSize());
   		}
   	}
   	public PageTableVO(Page page,MgPageable vo) {
   		if(page!=null){
   			setRowData(page.getContent());
   			setTotalCount(page.getTotalElements());
   		}
   		if(vo!=null){
   			setPageNo(vo.getPageNo());
   			setPageSize(vo.getPageSize());
   		}
   	}
   
   	public PageTableVO(Page page,BaseSearchPageVo vo) {
   		if(page!=null){
   			setRowData(page.getContent());
   			setTotalCount(page.getTotalElements());
   		}
   		if(vo!=null){
   			setPageNo(vo.getPageNo());
   			setPageSize(vo.getPageSize());
   		}
   	}
   
   
   	public List<T> getRowData() {
   		if(rowData==null){
   			rowData = new ArrayList<>();
   		}
   		return rowData;
   	}
   
   	public void setRowData(List<T> rowData) {
   		this.rowData = rowData;
   	}
   
   	public Object getExtendData() {
   		return extendData;
   	}
   
   	public void setExtendData(Object extendData) {
   		this.extendData = extendData;
   	}
   
   }
   
   ```
   
   
   ```java
   package com.xiushang.framework.entity.vo;
   
   import io.swagger.annotations.ApiModelProperty;
   
   import java.io.Serializable;
   
   /**
    * 分页查询抽象类
    */
   public abstract class MgPageable implements Serializable {
   
       /**
        * 当前的页数
        */
       @ApiModelProperty(notes = "当前的页数")
       private int pageNo = 1;
   
       /**
        * 当前每页所显示的行数。
        */
       @ApiModelProperty(notes = "当前每页所显示的行数")
       private int pageSize = 15;
       /**
        * 总行数。
        */
       @ApiModelProperty(notes = "总行数")
       private long totalCount = 0;
   
       @ApiModelProperty(notes = "是否有更多")
       private Boolean hasMore = false;
   
       public int getPageNo() {
           return pageNo;
       }
   
       public void setPageNo(int pageNo) {
           this.pageNo = pageNo;
       }
   
       public int getPageSize() {
           return pageSize;
       }
   
       public void setPageSize(int pageSize) {
           this.pageSize = pageSize;
       }
   
       public long getTotalCount() {
           return totalCount;
       }
   
       public void setTotalCount(long totalCount) {
           this.totalCount = totalCount;
       }
   
   
   
       public Boolean getHasMore() {
           return getTotalCount()>(getPageSize()*getPageNo());
       }
   
       public void setHasMore(Boolean hasMore) {
           this.hasMore = hasMore;
       }
   
   }
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] liukefu2050 commented on issue #10459: DubboService 和 @Transactional 一起配置事务失效

Posted by GitBox <gi...@apache.org>.
liukefu2050 commented on issue #10459:
URL: https://github.com/apache/dubbo/issues/10459#issuecomment-1216248566

   测试仓库:
   https://github.com/liukefu2050/DubboTransactional.git


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] AlbumenJ commented on issue #10459: DubboService 和 @Transactional 一起配置事务失效

Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on issue #10459:
URL: https://github.com/apache/dubbo/issues/10459#issuecomment-1214570914

   这个和 Dubbo 没啥关系,是你的 `com.xiushang.framework.entity.vo.PageTableVO` 不支持 `@transactional`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] liukefu2050 commented on issue #10459: DubboService 和 @Transactional 一起配置事务失效

Posted by GitBox <gi...@apache.org>.
liukefu2050 commented on issue #10459:
URL: https://github.com/apache/dubbo/issues/10459#issuecomment-1233896434

   [已解决,参见](https://github.com/liukefu2050/DubboTransactional.git)
   [参考文章](https://www.pudn.com/news/628f843dbf399b7f351ee78d.html)
   原因:dubbo 不能序列化hibernate 中Lazy,persistent 对象。需要引入hibernate 对象序列化实现
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] liukefu2050 commented on issue #10459: DubboService 和 @Transactional 一起配置事务失效

Posted by GitBox <gi...@apache.org>.
liukefu2050 commented on issue #10459:
URL: https://github.com/apache/dubbo/issues/10459#issuecomment-1233891196

   [wen](https://www.pudn.com/news/628f843dbf399b7f351ee78d.html)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] AlbumenJ commented on issue #10459: DubboService 和 @Transactional 一起配置事务失效

Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on issue #10459:
URL: https://github.com/apache/dubbo/issues/10459#issuecomment-1216059688

   https://stackoverflow.com/questions/11746499/how-to-solve-the-failed-to-lazily-initialize-a-collection-of-role-hibernate-ex 看一下这篇呢


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] liukefu2050 commented on issue #10459: DubboService 和 @Transactional 一起配置事务失效

Posted by GitBox <gi...@apache.org>.
liukefu2050 commented on issue #10459:
URL: https://github.com/apache/dubbo/issues/10459#issuecomment-1214640773

   你好,感谢回复,能具体点吗?如何解决这个问题?service我改造成dubbo之前,功能正常的啊,变成DubboService,才不行的。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] liukefu2050 closed issue #10459: DubboService 和 @Transactional 一起配置事务失效

Posted by GitBox <gi...@apache.org>.
liukefu2050 closed issue #10459: DubboService 和 @Transactional 一起配置事务失效
URL: https://github.com/apache/dubbo/issues/10459


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org