异常如下:
客户端:
Cannot access Hessian service at [http://远程ip/remote/authService]; nested exception is com.caucho.hessian.io.HessianProtocolException: 500: java.io.IOException: Server returned HTTP response code: 500 for URL:
服务端:
com.caucho.hessian.io.IOExceptionWrapper: java.lang.ClassNotFoundException: long
解决:我本来要同步school对象的(school和actCode对象是一对一),结果school中含有actCode信息,所以出现这种错误,school.setActCode(null);即可.
出现这个问题时,百思不得其解啊,看控制台输出提示是hessian反序列化过程中出现问题,看来问题出现在上传的对象中,debug后发现了问题所在,看来还是实践出真知啊,
总结:
以后远程调用时尽量不要直接操作po,以免出现不必要的问题(hessian不能操作复杂的对象)
以下是一对一关系,以前一般用一对多,对一对一关系还是有点生疏.
school.hbm.xml
<one-to-one name=
"actcode" class=
"SysActCode" cascade=
"save-update" outer-join=
"auto" constrained=
"true"/>
SysActCode.hbm.xml
<one-to-one name=
"school" class=
"School" cascade=
"save-update" outer-join=
"true" constrained=
"false"/>
School school = this.getSchoolInfoService().getModel(this.getId());
//Hibernate:select s.ID, s.manager,... from school_info s where s.ID=?
if(school.getActcode()!=null){
//这里不为null;
/** * 但是System.out.println(school.getActcode());会抛出异常: * LazyInitializationException:could not initialize proxy,the owning Session was closed * 看来hibernate先用代理对象标识一下而已,在取值时才加载对象, */
}
one-to-one,many-to-one的lazy默认为proxy,并且只能为false或proxy或no-proxy,不能为true;
单点关联中lazy可以设置:
lazy (可选 - 默认为 proxy): 默认情况下,单点关联是经过代理的
lazy= "no-proxy"指定此属性应该在实例变量第一次被访问时应该延迟抓取(fetche lazily)需要运行时字节码的增强)
lazy= "false"指定此关联总是被预先抓取