一个解决burlap hession 不支持hibernate延迟加载的方法

关于spring remoting支持,有四种方案:
1. 传统RMI.spring简化了RMI开发: JNDI没有启动时会自动启动/支持普通对象发布为RMI服务.
2. 基于http invoker.http+二进制序列化.缺点:不支持回调
3. 基于caucho的Hessian.http+二进制序列化.
4. 基于caucho的Burlap. http+xml序列化.

不过在burlap hession 中序列化延迟加载的hibernate对象时就会出现问题
因为它们在序列化对象时会试图加载所有的相关对象 此时session可能已关闭
而在反序列化po时,所有po的持久化状态都不能带过来 而是以默认的未持久化状态
所以你访问的时候 又会抛出Exception

现在知道什么原因引起的了,下面的工作就简单了,分别修改服务器端和客户端的代码
1.服务器端对延迟加载的对象直接以空对象代替
2.客户端把所有的po以普通对象或集合代替
以集合为例:
CollectionSerializer.java
package com.caucho.burlap.io;

......
public class CollectionSerializer extends Serializer {
......
public void writeObject(Object obj, AbstractBurlapOutput out)
            throws IOException {
            .....
        if ((list instanceof PersistentCollection)
                && !((PersistentCollection) list).wasInitialized()) {
            log.warn("try to serialise not initialized collection :"
                    + obj.getClass().getName() + "; filled null value");
            out.writeListBegin(0, obj.getClass().getName());
            out.writeListEnd();
        } else {
        .......

CollectionDeserializer.java
......
public Object readList(AbstractBurlapInput in, int length)
            throws IOException {
            ......
        else if (Collection.class.equals(_type))
            list = new ArrayList();
        else if (PersistentSet.class.equals(_type)){
            log.debug("make a Arraylist for PersistentCollection");
            list = new HashSet();
        }else if (PersistentList.class.equals(_type)){
            log.debug("make a Arraylist for PersistentCollection");
            list = new ArrayList();
        }
        ......

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值