0000
作家
作家
  • 铜币143枚
  • 威望34点
  • 贡献值1点
阅读:2061回复:6

Spring web服务的问题

楼主#
更多 发布于:2006-04-18 10:05
我靠,6688(不是什么奇怪的手机型号)

远程接口;
 
import java.util.Collection;
import java.util.Date;

import cn.edu.bigc.share.pojo.ResourceInfo;

public interface ResourceService {
   public void addResource(ResourceInfo res);
   public ResourceInfo getResource(String uid);
   /**
    * Get new added resources.
    * @param from time of last synchronize
    * @return a Collection of Resource
    */
   public Collection getNewResource(Date from);
   
}



本地调用:
 
Collection newResource = resourceService.getNewResource(from);


远程服务端日志显示public Collection getNewResource(Date from);执行成功,但是在客户端显示错误了,好像是序列化的错误。

错误信息如下:
org.springframework.remoting.RemoteAccessException: Cannot access Hessian service at [
http://localhost:8080/share/remoting/resourceService
]; nested exception is com.caucho.hessian.io.HessianProtocolException: expected string at [ 2006-04-18 10:06:51 0000 修改 ]
.--. |o_o | |:_/ | // \ \ (| | ) /'\_ _/`\ \___)=(___/
0000
作家
作家
  • 铜币143枚
  • 威望34点
  • 贡献值1点
1C#
发布于:2006-04-18 10:08
Re:Spring web服务的问题
我晕……为什么Stack trace就是帖不上……

org.springframework.remoting.RemoteAccessException: Cannot access Hessian service at [
http://localhost:8080/share/remoting/resourceService
]; nested exception is com.caucho.hessian.io.HessianProtocolException: expected string at
.--. |o_o | |:_/ | // \ \ (| | ) /'\_ _/`\ \___)=(___/
0000
作家
作家
  • 铜币143枚
  • 威望34点
  • 贡献值1点
2C#
发布于:2006-04-18 12:13
Re:Spring web服务的问题
基本上找到问题了,hibernate的lazy原因

在返回之前已经closeSession()了,返回后框架进行序列化时要读入信息,然session已经关闭了,所以报错了,但是也不能不用lazy,因为lazy内容可能是一个巨大的set集。
.--. |o_o | |:_/ | // \ \ (| | ) /'\_ _/`\ \___)=(___/
0000
作家
作家
  • 铜币143枚
  • 威望34点
  • 贡献值1点
3C#
发布于:2006-04-18 14:37
Re:Spring web服务的问题
某人说重发一遍

远程接口;
import java.util.Collection;
import java.util.Date;

import cn.edu.bigc.share.pojo.ResourceInfo;

public interface ResourceService {
	public void addResource(ResourceInfo res);
	public ResourceInfo getResource(String uid);
	/**
	 * Get new added resources.
	 * @param from time of last synchronize
	 * @return a Collection of Resource
	 */
	public Collection getNewResource(Date from);
	
}


本地调用:
Collection newResource = resourceService.getNewResource(from);


远程服务端日志显示public Collection getNewResource(Date from);执行成功,但是在客户端显示错误了,好像是序列化的错误。

错误信息如下:

org.springframework.remoting.RemoteAccessException: Cannot access Hessian service at [
				http://localhost:8080/share/remoting/resourceService
			]; nested exception is com.caucho.hessian.io.HessianProtocolException: 
com.caucho.hessian.io.HessianProtocolException: 
	at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:171)
	at $Proxy0.getNewResource(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.springframework.remoting.caucho.HessianClientInterceptor.invoke(HessianClientInterceptor.java:115)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
	at $Proxy1.getNewResource(Unknown Source)
	at cn.edu.bigc.share.service.IndexServiceImpl.updateIndex(IndexServiceImpl.java:26)
	at cn.edu.bigc.share.service.IndexServiceImplTest.testUpdateIndex(IndexServiceImplTest.java:13)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
.--. |o_o | |:_/ | // \ \ (| | ) /'\_ _/`\ \___)=(___/
0000
作家
作家
  • 铜币143枚
  • 威望34点
  • 贡献值1点
4C#
发布于:2006-04-18 14:40
Re:Spring web服务的问题
org.springframework.remoting.RemoteAccessException: Cannot access Hessian service at [
				http://localhost:8080/share/remoting/resourceService
			]; nested exception is com.caucho.hessian.io.HessianProtocolException: 
com.caucho.hessian.io.HessianProtocolException: 
	at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java:171)
	at $Proxy0.getNewResource(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.springframework.remoting.caucho.HessianClientInterceptor.invoke(HessianClientInterceptor.java:115)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
	at $Proxy1.getNewResource(Unknown Source)
	at cn.edu.bigc.share.service.IndexServiceImpl.updateIndex(IndexServiceImpl.java:26)
	at cn.edu.bigc.share.service.IndexServiceImplTest.testUpdateIndex(IndexServiceImplTest.java:13)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
.--. |o_o | |:_/ | // \ \ (| | ) /'\_ _/`\ \___)=(___/
southeast
著名写手
著名写手
  • 铜币0枚
  • 威望0点
  • 贡献值0点
5C#
发布于:2006-04-18 18:33
Re:Spring web服务的问题
用initialize方法
[img]http://www.wait4c.com/bbs/userfiles/2196/2005051614543457820.jpg[/img]
0000
作家
作家
  • 铜币143枚
  • 威望34点
  • 贡献值1点
6C#
发布于:2006-04-19 18:49
Re:Spring web服务的问题

静态方法Hibernate.initialized()  为你的应用程序提供了一个便捷的途径来延迟加载集合或代理。 只要它的Session处于open状态,Hibernate.initialize(cat) 将会为cat强制对代理实例化。 同样,Hibernate.initialize( cat.getKittens() ) 对kittens的集合具有同样的功能


 有时候,你并不需要完全实例化整个大的集合,仅需要了解它的部分信息(例如其大小)、或者集合的部分内容。

你可以使用集合过滤器得到其集合的大小,而不必实例化整个集合:

( (Integer) s.createFilter( collection, "select count(*)" ).list().get(0) ).intValue()

这里的createFilter()方法也可以被用来有效的抓取集合的部分内容,而无需实例化整个集合:

s.createFilter( lazyCollection, "").setFirstResult(0).setMaxResults(10).list();


有的东西我连它的大小也不要知道,我把多佘的东西都setXXX(null)了~~
由hibernate引起的原因没有了
另:2.x版本的Hessian在处理数组数据的时候存在一个bug(已证实),估计对collection对象也有这个bug(错误报告基本相同),换到了3.0版。


到这里:
现在还是有问题,在客户端居然报错了:
18:39:27,176ERRORLazyInitializationException:19-failed to lazily initialize a collection - no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection - no session or session was closed
	at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
	at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
	at org.hibernate.collection.AbstractPersistentCollection.write(AbstractPersistentCollection.java:61)
	at org.hibernate.collection.PersistentSet.add(PersistentSet.java:158)
	at com.caucho.hessian.io.CollectionDeserializer.readList(CollectionDeserializer.java)
	at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java)
	at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:150)
	at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:107)
	at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java)
	at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:150)
	at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:107)
	at com.caucho.hessian.io.SerializerFactory.readMap(SerializerFactory.java)
	at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java:1126)
	at com.caucho.hessian.io.CollectionDeserializer.readList(CollectionDeserializer.java)
	at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java)
	at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:150)
	at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:107)
	at com.caucho.hessian.io.SerializerFactory.readMap(SerializerFactory.java)
	at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java:1126)
	at com.caucho.hessian.io.CollectionDeserializer.readList(CollectionDeserializer.java)
	at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java)
	at com.caucho.hessian.io.HessianInput.readReply(HessianInput.java:285)
	at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java)
	at $Proxy0.getNewResource(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.springframework.remoting.caucho.HessianClientInterceptor.invoke(HessianClientInterceptor.java:115)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
	at $Proxy1.getNewResource(Unknown Source)
	at cn.edu.bigc.share.service.IndexServiceImpl.updateIndex(IndexServiceImpl.java:26)
	at cn.edu.bigc.share.service.IndexServiceImplTest.testUpdateIndex(IndexServiceImplTest.java:13)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
org.hibernate.LazyInitializationException: failed to lazily initialize a collection - no session or session was closed
	at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:191)
	at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:183)
	at org.hibernate.collection.AbstractPersistentCollection.write(AbstractPersistentCollection.java:61)
	at org.hibernate.collection.PersistentSet.add(PersistentSet.java:158)
	at com.caucho.hessian.io.CollectionDeserializer.readList(CollectionDeserializer.java)
	at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java)
	at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:150)
	at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:107)
	at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java)
	at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:150)
	at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:107)
	at com.caucho.hessian.io.SerializerFactory.readMap(SerializerFactory.java)
	at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java:1126)
	at com.caucho.hessian.io.CollectionDeserializer.readList(CollectionDeserializer.java)
	at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java)
	at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:150)
	at com.caucho.hessian.io.JavaDeserializer.readMap(JavaDeserializer.java:107)
	at com.caucho.hessian.io.SerializerFactory.readMap(SerializerFactory.java)
	at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java:1126)
	at com.caucho.hessian.io.CollectionDeserializer.readList(CollectionDeserializer.java)
	at com.caucho.hessian.io.HessianInput.readObject(HessianInput.java)
	at com.caucho.hessian.io.HessianInput.readReply(HessianInput.java:285)
	at com.caucho.hessian.client.HessianProxy.invoke(HessianProxy.java)
	at $Proxy0.getNewResource(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.springframework.remoting.caucho.HessianClientInterceptor.invoke(HessianClientInterceptor.java:115)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
	at $Proxy1.getNewResource(Unknown Source)
	at cn.edu.bigc.share.service.IndexServiceImpl.updateIndex(IndexServiceImpl.java:26)
	at cn.edu.bigc.share.service.IndexServiceImplTest.testUpdateIndex(IndexServiceImplTest.java:13)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)



强烈不解……setXX(null)已经初始化了嘛,而且服务器端日志也没有记录错误了,正确地记下了返回值的所有field的值

等下试试initialize

----------------

但是还是觉得奇怪,在客户端,数据经过传递,应该已经和hibernate脱离关系了啊

有一点说明:这里的“服务端”和“客户端”只是在此web service会话中的意义,从物理上叫是完全对等的server. 同样的spring+hibernate
.--. |o_o | |:_/ | // \ \ (| | ) /'\_ _/`\ \___)=(___/
游客

返回顶部